Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMAKE with RAJA CUDA backend #1654

Closed
yencal opened this issue May 22, 2024 · 4 comments
Closed

CMAKE with RAJA CUDA backend #1654

yencal opened this issue May 22, 2024 · 4 comments

Comments

@yencal
Copy link

yencal commented May 22, 2024

I get this error when building a project using the RAJA CUDA backend.

/home/cyenusah/Project/hpc-heterogeneous-computing/src/daxpy/raja/raja_example/main.cpp: In function ‘int main(int, char**)’:
/home/cyenusah/Project/hpc-heterogeneous-computing/src/daxpy/raja/raja_example/main.cpp:37:24: error: ‘cuda_exec’ in namespace ‘RAJA’ does not name a template type
   37 |   using policy = RAJA::cuda_exec<256>;

Here is my CMakeLists.txt file

cmake_minimum_required(VERSION 3.17)
set(CMAKE_CXX_STANDARD 17) 
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

set(THIS raja-example)

project(${THIS})

if (NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)

find_package(RAJA REQUIRED)

set(SOURCE main.cpp)

add_executable(${THIS} ${SOURCE})

target_link_libraries(${THIS} PRIVATE RAJA)

I installed RAJA using the ENABLE_CUDA cmake build flag, and it appears to install correctly since the examples that come with RAJA run the cuda backend when I execute them.

Please help on how to correctly use cmake for a project that used RAJA CUDA backend. Thanks.

@rhornung67
Copy link
Member

How did you run CMake to configure the build for your project? Did you pass -DENABLE_CUDA=On?

@yencal
Copy link
Author

yencal commented May 23, 2024

@rhornung67 thanks for the suggestion. However when I do cmake -DENABLE_CUDA=On ../, I get this warning from cmake

CMake Warning:
  Manually-specified variables were not used by the project:

    ENABLE_CUDA

If I go ahead and run make anyway, I get the same error:

/home/cyenusah/Project/hpc-heterogeneous-computing/src/daxpy/raja/raja_example/main.cpp: In function ‘int main(int, char**)’:
/home/cyenusah/Project/hpc-heterogeneous-computing/src/daxpy/raja/raja_example/main.cpp:37:24: error: ‘cuda_exec’ in namespace ‘RAJA’ does not name a template type
   37 |   using policy = RAJA::cuda_exec<256>;

@davidbeckingsale
Copy link
Member

davidbeckingsale commented May 23, 2024

It looks like your example is using CUDA, so you will need to tell CMake to compile your main.cpp file with CUDA, e.g.:

set_source_files_properties(main.cpp PROPERTIES LANGUAGE CUDA)

You will also need to add enable_language(CUDA) to your CMakeLists

@yencal
Copy link
Author

yencal commented May 23, 2024

@davidbeckingsale. Thanks for the suggestions. I had to add set(CMAKE_CUDA_HOST_COMPILER gcc) and set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --extended-lambda") in addition to your suggestions to get it working.

Here is the final CMakeLists.txt that worked for me.

cmake_minimum_required(VERSION 3.17)
set(CMAKE_CXX_STANDARD 17) 
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

set(THIS raja-example)

project(${THIS})
enable_language(CUDA)
set(CMAKE_CUDA_HOST_COMPILER gcc)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --extended-lambda")

if (NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)

find_package(RAJA REQUIRED)

set(SOURCE main.cpp)
set_source_files_properties(${SOURCE} PROPERTIES LANGUAGE CUDA)
add_executable(${THIS} ${SOURCE})

target_link_libraries(${THIS} PRIVATE RAJA)

I used cmake ../ and found that -DENABLE_CUDA=ON did nothing.

@yencal yencal closed this as completed May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants