ROCm / HIP-CPU

An implementation of HIP that works on CPUs, across OSes.
MIT License
112 stars 19 forks source link

Do some template magic so we don't have to cast to void** #26

Closed jakub-homola closed 1 year ago

jakub-homola commented 3 years ago

The following example line of code

hipMalloc(&d_x, count * sizeof(float));

fails to compile (using g++ 9.4.0) with error

saxpy.hip.cpp:46:15: error: invalid conversion from ‘float**’ to ‘void**’ [-fpermissive]
   46 |     hipMalloc(&d_x, count * sizeof(float));
      |               ^~~~
      |               |
      |               float**

I know the fix is to just cast the pointer,

hipMalloc((void**)&d_x, count * sizeof(float));

but who likes that? CUDA and HIP don't require the cast, so neither should HIP-CPU. In the classic HIP (include/hip_runtime_api.h right at the bottom in 4.3) there is the function

template <class T>
static inline hipError_t hipMalloc(T** devPtr, size_t size) {
    return hipMalloc((void**)devPtr, size);
}

so please do something similar in HIP-CPU too, for all similar functions. If there are any cons to this, please explain or point me to an explanation.

Thanks, Jakub Homola

Edit: I am using the current HIP-CPU master branch, changelog says version 0.1.4142 from December 2020