HIPIFY icon indicating copy to clipboard operation
HIPIFY copied to clipboard

[HIPIFY] HIPIFY converts CUDA_R_32F to HIPBLAS_R_32F instead of HIP_R_32F

Open hom0056 opened this issue 3 years ago • 3 comments

When hipifying cuda source containing cusparse code, CUDA_R_32F (of type cudaDataType) should be converted to HIP_R_32F (of type hipDataType), which is, according to nvcc_detail/hip_runtime_api.h, just a macro definition of the original cuda type and value. Instead, CUDA_R_32F gets hipified to HIPBLAS_R_32F, which is of type hipblasDatatype_t and is incompatible.

The original cuda code gets compiled using nvcc with no problem and runs OK, but after hipification, compilation with hipcc fails with errors like

my_sparse_test.hip.cpp(109): error: argument of type "hipblasDatatype_t" is incompatible with parameter of type "cudaDataType"

pointing to a line where (for example) hipsparseSpMV function is called.

Replacing HIPBLAS_R_32F with HIP_R_32F in the hipified code makes the code compile with no problem and the program runs OK.

I am on nvidia platform, using Ubuntu-18.04. hipcc --version:

HIP version: 4.2.21155-37cb3a34
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Wed_Jun__2_19:15:15_PDT_2021
Cuda compilation tools, release 11.4, V11.4.48
Build cuda_11.4.r11.4/compiler.30033411_0

hipify-clang --version:

LLVM (http://llvm.org/):
  LLVM version 12.0.1
  Optimized build.
  Default target: x86_64-unknown-linux-gnu
  Host CPU: znver1

this probably applies to other values of the enum as well. this applies to both hipify-perl and hipify-clang

edit: on my amd-gpu machine the error message from hipcc is

my_sparse_test.hip.cpp:119:5: error: no matching function for call to 'hipsparseSpMV'
    hipsparseSpMV(sparseHandle, HIPSPARSE_OPERATION_NON_TRANSPOSE, &alpha, matA, vecX, &beta, vecY, HIPBLAS_R_32F, HIPSPARSE_MV_ALG_DEFAULT, workspace);
    ^~~~~~~~~~~~~
/home/hom0056/apps/hipSPARSE/installation/include/hipsparse.h:5510:19: note: candidate function not viable: no known conversion from 'hipblasDatatype_t' to 'hipDataType' for 8th argument

the cause seems to be the same.

hom0056 avatar Aug 11 '21 12:08 hom0056

@hom0056, Could you provide your example, please?

emankov avatar Aug 11 '21 14:08 emankov

Sure. The simplest cuda program I can think of that produces the problem:

#include <cusparse.h>
#include <cublas_v2.h>

int main()
{
    int size = 10;

    float * d_x;
    cudaMalloc(&d_x, size * sizeof(float));

    cusparseHandle_t sparseHandle;
    cusparseCreate(&sparseHandle);

    cusparseDnVecDescr_t vec;
    cusparseCreateDnVec(&vec, size, d_x, CUDA_R_32F);
    cusparseDestroyDnVec(vec);

    cudaFree(d_x);
    
    cusparseDestroy(sparseHandle);

    return 0;
}

then hipify-clang my_sparse_test.cu -o my_sparse_test.hip.cpp and hipcc [includeflags] my_sparse_test.hip.cpp -o my_sparse_test.x [libflags] Not including the cublas header just changes the error to error: identifier "HIPBLAS_R_32F" is undefined

If you need, I can also provide the full program I was hipifying originally.

hom0056 avatar Aug 11 '21 19:08 hom0056

Hi @hom0056,

This issue will be fixed after fixing https://github.com/ROCmSoftwarePlatform/hipBLAS/issues/366 in hipBLAS and HIP.

emankov avatar Aug 18 '21 15:08 emankov

Finally fixed in hipBLAS 6.0.0 and HIPIFY tools (#1065).

emankov avatar Dec 28 '23 13:12 emankov