Skip to content

Commit

Permalink
[HIPIFY][fix] cudaMallocHost -> hipHostMalloc
Browse files Browse the repository at this point in the history
+ Added the last argument `hipHostMallocDefault` as `unsigned int flags`, because there is no default value for it
  • Loading branch information
emankov committed Feb 9, 2024
1 parent 54f9d5c commit 2383fb9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/HipifyAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ const std::string sCusparseSpMM_bufferSize = "cusparseSpMM_bufferSize";
const std::string sCusparseSpSM_analysis = "cusparseSpSM_analysis";
const std::string sCusparseSpSM_solve = "cusparseSpSM_solve";
const std::string sCusparseXcsrgeam2Nnz = "cusparseXcsrgeam2Nnz";
const std::string sCudaMallocHost = "cudaMallocHost";

// CUDA_OVERLOADED
const std::string sCudaEventCreate = "cudaEventCreate";
Expand Down Expand Up @@ -269,6 +270,13 @@ std::map<std::string, hipify::FuncOverloadsStruct> FuncOverloads {
};

std::map<std::string, ArgCastStruct> FuncArgCasts {
{sCudaMallocHost,
{
{
{2, {e_add_const_argument, cw_None, "hipHostMallocDefault"}}
}
}
},
{sCudaMemcpyToSymbol,
{
{
Expand Down Expand Up @@ -2574,7 +2582,8 @@ std::unique_ptr<clang::ASTConsumer> HipifyAction::CreateASTConsumer(clang::Compi
sCusparseSpMM_bufferSize,
sCusparseSpSM_analysis,
sCusparseSpSM_solve,
sCusparseXcsrgeam2Nnz
sCusparseXcsrgeam2Nnz,
sCudaMallocHost
)
)
)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/device/device_symbols.cu
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ int main() {
}
// CHECK: hipMalloc((void**)&Ad, SIZE);
cudaMalloc((void**)&Ad, SIZE);
// CHECK: hipHostMalloc((void**)&Am, SIZE);
// CHECK: hipHostMalloc((void**)&Am, SIZE, hipHostMallocDefault);
cudaMallocHost((void**)&Am, SIZE);
// CHECK: hipHostMalloc((void**)&Cm, SIZE);
// CHECK: hipHostMalloc((void**)&Cm, SIZE, hipHostMallocDefault);
cudaMallocHost((void**)&Cm, SIZE);
for (int i = 0; i < NUM; ++i) {
Am[i] = -1 * i;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/synthetic/runtime_functions.cu
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ int main() {

// CUDA: extern __host__ cudaError_t CUDARTAPI cudaMallocHost(void **ptr, size_t size);
// HIP: hipError_t hipHostMalloc(void** ptr, size_t size, unsigned int flags);
// CHECK: result = hipHostMalloc(&deviceptr, bytes);
// CHECK: result = hipHostMalloc(&deviceptr, bytes, hipHostMallocDefault);
result = cudaMallocHost(&deviceptr, bytes);

// CUDA: extern __host__ __cudart_builtin__ cudaError_t CUDARTAPI cudaMallocManaged(void **devPtr, size_t size, unsigned int flags = cudaMemAttachGlobal);
Expand Down

0 comments on commit 2383fb9

Please sign in to comment.