wlav / cppyy

Other
384 stars 38 forks source link

Macro redefined '__CLING__GNUC__' warning while running sample CUDA code #232

Open chococandy63 opened 2 months ago

chococandy63 commented 2 months ago

I was running a sample CUDA code in cppyy

import cppyy
import os
os.environ['CLING_ENABLE_CUDA']='1'
os.environ['CLING_CUDA_PATH']='/usr/include/cuda'
os.environ['CLING_CUDA_ARCH']='sm_86'
cppyy.add_include_path('/usr/include/cuda')
cppyy.add_library_path('/usr/lib/cuda')
cppyy.include('iostream')
cppyy.include('cuda_runtime.h')
cppyy.load_library('cudart')
cppyy.cppdef('''
void cuda_information() {
    int version;
    cudaRuntimeGetVersion(&version);
    std::cout << "CUDA version: " << version << std::endl;
             int deviceCount;
             cudaGetDeviceCount(&deviceCount);
             std::cout << "CUDA Devices: " << deviceCount << std::endl;
             for (int i = 0; i < deviceCount; i++) {
                cudaDeviceProp deviceProp;
                cudaGetDeviceProperties(&deviceProp, i);
                std::cout << "Device " << i << ": " << deviceProp.name << std::endl;
                std:: cout << "Device ID: " << i << std::endl;
                std::cout << "Total global memory: " << deviceProp.totalGlobalMem << std::endl;
                std::cout << "Shared memory per block: " << deviceProp.sharedMemPerBlock << std::endl;
                std::cout << "Registers per block: " << deviceProp.regsPerBlock << std::endl;
             }
}
''')
cppyy.gbl.cuda_information()

I found the following warnings with the output.

<built-in>:8:9: warning: '__CLING__GNUC__' macro redefined [-Wmacro-redefined]
#define __CLING__GNUC__ 11
        ^
<built-in>:459:9: note: previous definition is here
#define __CLING__GNUC__ 9
        ^
<built-in>:9:9: warning: '__CLING__GNUC_MINOR__' macro redefined [-Wmacro-redefined]
#define __CLING__GNUC_MINOR__ 4
        ^
<built-in>:460:9: note: previous definition is here
#define __CLING__GNUC_MINOR__ 3
        ^
CUDA version: 11050
CUDA Devices: 1
Device 0: NVIDIA GeForce GTX 1650
Device ID: 0
Total global memory: 4093509632
Shared memory per block: 49152
Registers per block: 65536 

Any hints how they can be fixed? I have tried both the methods(rebuilding PCH and make -k clean) mentioned here Issue#223 but still the warnings persists. Maybe I am missing something very trivial but I am new to the project and trying to contribute as much as I can in my capacity :)

wlav commented 1 month ago

The error message as posted in the other report is independent of CUDA, right? In which case it has to be an environment mixup with the PCH needing rebuilding.

I'd caution for the CUDA case that CUDA is picky about the g++ compiler headers it supports. If there are multiple versions on your system, it may pull in a non-default one.

chococandy63 commented 1 month ago

Yes, it is independent of CUDA.