jacob-carlborg / dstep

A tool for converting C and Objective-C headers to D modules
204 stars 37 forks source link

/usr/include/cuda_runtime_api.h ==> d: Error: undefined identifier `cudaError_t` #280

Open mw66 opened 2 years ago

mw66 commented 2 years ago
$ dstep --version
1.0.3-2-g2f6e8ae

$ dstep /usr/include/cuda_runtime_api.h -o cuda_runtime_api.d

# but the generated file cannot be compiled:

source/cuda_runtime_api.d(3625,13): Error: undefined identifier `cudaError_t`
source/cuda_runtime_api.d(3625,13): Error: undefined identifier `cudaExternalSemaphore_t`
source/cuda_runtime_api.d(3625,13): Error: undefined identifier `cudaExternalSemaphoreSignalParams`
source/cuda_runtime_api.d(3625,13): Error: undefined identifier `cudaStream_t`
source/cuda_runtime_api.d(3701,13): Error: undefined identifier `cudaError_t`
source/cuda_runtime_api.d(3701,13): Error: undefined identifier `cudaExternalSemaphore_t`
source/cuda_runtime_api.d(3701,13): Error: undefined identifier `cudaExternalSemaphoreWaitParams`
source/cuda_runtime_api.d(3701,13): Error: undefined identifier `cudaStream_t`
source/cuda_runtime_api.d(158,22): Error: undefined identifier `__device__`
source/cuda_runtime_api.d(200,13): Error: undefined identifier `cudaError_t`
source/cuda_runtime_api.d(221,13): Error: undefined identifier `cudaError_t`
source/cuda_runtime_api.d(308,13): Error: undefined identifier `cudaError_t`
source/cuda_runtime_api.d(308,13): Error: undefined identifier `cudaLimit`
source/cuda_runtime_api.d(343,13): Error: undefined identifier `cudaError_t`
source/cuda_runtime_api.d(343,13): Error: undefined identifier `cudaLimit`
source/cuda_runtime_api.d(365,13): Error: undefined identifier `cudaError_t`
source/cuda_runtime_api.d(365,13): Error: undefined identifier `cudaChannelFormatDesc`
source/cuda_runtime_api.d(398,13): Error: undefined identifier `cudaError_t`
source/cuda_runtime_api.d(398,13): Error: undefined identifier `cudaFuncCache`
source/cuda_runtime_api.d(435,13): Error: undefined identifier `cudaError_t`

Shall this generated cuda_runtime_api.d be self-contained? or I need to find the .h which defined cudaError_t, and include those files in the D/step build?

mw66 commented 2 years ago

btw, it's defined in another included file:

/usr/include/driver_types.h

typedef __device_builtin__ enum cudaError cudaError_t;
mw66 commented 2 years ago

Found work-around: let dstep work on the cpp preprocessed output .i file:

$ gcc -E /usr/include/cuda_runtime_api.h > cuda_runtime_api.i
$ dstep ./cuda_runtime_api.i -o cuda_runtime_api.d

Maybe you can add this tip to the README to help other users?

jacob-carlborg commented 2 years ago

Please include the input and the expected output.

jacob-carlborg commented 2 years ago

Shall this generated cuda_runtime_api.d be self-contained? or I need to find the .h which defined cudaError_t, and include those files in the D/step build?

Most generated D files will not be self contained if the header file is not. So yes, you need to find where the symbols are defined and generate D files for those as well and manually import the D files.

jacob-carlborg commented 2 years ago

At one point I would like to make DStep operate on a whole directory of header files. Then it can hopefully import the D files automatically.

mw66 commented 2 years ago

Please include the input and the expected output.

$ dpkg -S /usr/include/cuda_runtime_api.h nvidia-cuda-dev:amd64: /usr/include/cuda_runtime_api.h

$ wc /usr/include/cuda_runtime_api.h 12077 67841 509599 /usr/include/cuda_runtime_api.h

$ dpkg -l nvidia-cuda-dev Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-=====================-===============-============-================================= ii nvidia-cuda-dev:amd64 11.2.2-1ubuntu1 amd64 NVIDIA CUDA development files

It needs lots of related headers to be compiled, so that's why in the end, I choose to run dstep on the cpp output