ROCm / HIP-CPU

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

Missing API function: hipMallocPitch & hipMemcpy2D #23

Closed ueqri closed 2 years ago

ueqri commented 2 years ago

According to HIP API docs, hipMallocPitch and related hipMemcpy2D are fully supported by HIP.

But when I build the HIP codes with HIP-CPU, the errors occur on hipMallocPitch and hipMemcpy2D, which are not declared in HIP-CPU runtime library.

The minimal code is here:

#include <hip/hip_runtime_api.h>

int main()
{
  int row = 10, col = 10;
  float h_ptr[row][col];
  float *d_ptr;
  size_t pitch;

  hipMallocPitch(&d_ptr, &pitch, col*sizeof(float), row);
  hipMemcpy2D(d_ptr, pitch, h_ptr, col*sizeof(float), col*sizeof(float), row, hipMemcpyHostToDevice);

  return 0;
}

After looking through the src/include/hip/detail/api.hpp & include/hip/hip_api.h, I found hipMemcpy2DAsync is the only implemented function related to the problem.

Since we could use the trivial way to implement those pitched memory in CPU simulation, could we just add the wrap for hipMallocPitch and hipMemcpy2D in HIP-CPU to avoid compiler errors? I'd be glad to contribute for this.

AlexVlx commented 2 years ago

Thank you for the patch!