CUDA language support with host compiler flags

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

CUDA language support with host compiler flags

CMake mailing list
Hi All!

I am trying to compile CUDA code with controlling both host and device compiler flags.

Currently my CMakeLists.txt looks like:

```
cmake_minimum_required(VERSION 3.8) # CUDA language support

project(CUDA_test LANGUAGES CXX CUDA)

if (MSVC)
  string(REGEX REPLACE "/W[0-9]" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif (MSVC)

set(Hdrs)

set(Srcs Main.cu)

add_executable(${PROJECT_NAME} ${Hdrs} ${Srcs})

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

target_compile_options(${PROJECT_NAME} PRIVATE $<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall -Wextra -pedantic>
                                               $<$<CXX_COMPILER_ID:MSVC>:/W4>)

set_target_properties(${PROJECT_NAME} PROPERTIES CUDA_SEPARABLE_COMPILATION ON
                                                 CUDA_STANDARD 14
                                                 CUDA_STANDARD_REQUIRED ON
                                                 CUDA_EXTENSIONS OFF
                                                 CXX_STANDARD 14
                                                 CXX_STANDARD_REQUIRED ON
                                                 CXX_EXTENSIONS OFF)

source_group ("Headers" FILES ${Hdrs})
source_group ("Sources" FILES ${Srcs})
```

However, when I compile the code I get the following error:

[1/3] Building CUDA object CMakeFiles/CUDA_test.dir/Main.cu.o
FAILED: CMakeFiles/CUDA_test.dir/Main.cu.o
/usr/bin/nvcc   -I/var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL -g   -Wall -Wextra -pedantic -std=c++14 -x cu -dc /var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL/Main.cu -o CMakeFiles/CUDA_test.dir/Main.cu.o && /usr/bin/nvcc   -I/var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL -g   -Wall -Wextra -pedantic -std=c++14 -x cu -M /var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL/Main.cu -MT CMakeFiles/CUDA_test.dir/Main.cu.o -o CMakeFiles/CUDA_test.dir/Main.cu.o.d
nvcc fatal   : Unknown option 'Wall'
ninja: build stopped: subcommand failed.

CMake seems to pass -Wall -Wextra -pedantic to the device compiler as well, even though it is neither GNU nor Clang, but CUDA. How can I specify warning and similar flags separatly for the host and device compilers?

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Portion de message joint (862 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: CUDA language support with host compiler flags

CMake mailing list
You need to guard the flags with `$<COMPILE_LANGUAGE:CXX>` the
evaluation on a given compiler id is done for all sources of a target,
and not on each target source file.

So you will need something like:

set(cxx_flags "$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall
-Wextra -pedantic>
                                               $<$<CXX_COMPILER_ID:MSVC>:/W4")
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:${cxx_flags}>)

On Fri, Feb 22, 2019 at 4:11 AM Máté Ferenc Nagy-Egri via CMake
<[hidden email]> wrote:

>
> Hi All!
>
> I am trying to compile CUDA code with controlling both host and device compiler flags.
>
> Currently my CMakeLists.txt looks like:
>
> ```
> cmake_minimum_required(VERSION 3.8) # CUDA language support
>
> project(CUDA_test LANGUAGES CXX CUDA)
>
> if (MSVC)
>   string(REGEX REPLACE "/W[0-9]" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
> endif (MSVC)
>
> set(Hdrs)
>
> set(Srcs Main.cu)
>
> add_executable(${PROJECT_NAME} ${Hdrs} ${Srcs})
>
> target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
>
> target_compile_options(${PROJECT_NAME} PRIVATE $<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall -Wextra -pedantic>
>                                                $<$<CXX_COMPILER_ID:MSVC>:/W4>)
>
> set_target_properties(${PROJECT_NAME} PROPERTIES CUDA_SEPARABLE_COMPILATION ON
>                                                  CUDA_STANDARD 14
>                                                  CUDA_STANDARD_REQUIRED ON
>                                                  CUDA_EXTENSIONS OFF
>                                                  CXX_STANDARD 14
>                                                  CXX_STANDARD_REQUIRED ON
>                                                  CXX_EXTENSIONS OFF)
>
> source_group ("Headers" FILES ${Hdrs})
> source_group ("Sources" FILES ${Srcs})
> ```
>
> However, when I compile the code I get the following error:
>
> [1/3] Building CUDA object CMakeFiles/CUDA_test.dir/Main.cu.o
> FAILED: CMakeFiles/CUDA_test.dir/Main.cu.o
> /usr/bin/nvcc   -I/var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL -g   -Wall -Wextra -pedantic -std=c++14 -x cu -dc /var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL/Main.cu -o CMakeFiles/CUDA_test.dir/Main.cu.o && /usr/bin/nvcc   -I/var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL -g   -Wall -Wextra -pedantic -std=c++14 -x cu -M /var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL/Main.cu -MT CMakeFiles/CUDA_test.dir/Main.cu.o -o CMakeFiles/CUDA_test.dir/Main.cu.o.d
> nvcc fatal   : Unknown option 'Wall'
> ninja: build stopped: subcommand failed.
>
> CMake seems to pass -Wall -Wextra -pedantic to the device compiler as well, even though it is neither GNU nor Clang, but CUDA. How can I specify warning and similar flags separatly for the host and device compilers?
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: CUDA language support with host compiler flags

CMake mailing list

Hi Robert!

 

Thank you for the help. I don’t know if I could’ve find that solution myself. I guess selecting CUDA as the COMPILE_LANGUAGE I can controll .cu compiler options to select architecture and what not.

 

Anyhow, if someone needed the minimal template, here it is:

 

https://gist.github.com/MathiasMagnus/0edacac888a758fe233cb69f3e291d62

 

Cheers,

Máté

 

Feladó: [hidden email]
Elküldve: 2019. február 27., szerda 15:00
Címzett: [hidden email]
Másolatot kap: [hidden email]
Tárgy: Re: [CMake] CUDA language support with host compiler flags

 

You need to guard the flags with `$<COMPILE_LANGUAGE:CXX>` the

evaluation on a given compiler id is done for all sources of a target,

and not on each target source file.

 

So you will need something like:

 

set(cxx_flags "$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall

-Wextra -pedantic>

                                               $<$<CXX_COMPILER_ID:MSVC>:/W4")

target_compile_options(${PROJECT_NAME} PRIVATE

$<$<COMPILE_LANGUAGE:CXX>:${cxx_flags}>)

 

On Fri, Feb 22, 2019 at 4:11 AM Máté Ferenc Nagy-Egri via CMake

<[hidden email]> wrote:

> 

> Hi All!

> 

> I am trying to compile CUDA code with controlling both host and device compiler flags.

> 

> Currently my CMakeLists.txt looks like:

> 

> ```

> cmake_minimum_required(VERSION 3.8) # CUDA language support

> 

> project(CUDA_test LANGUAGES CXX CUDA)

> 

> if (MSVC)

>   string(REGEX REPLACE "/W[0-9]" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})

> endif (MSVC)

> 

> set(Hdrs)

> 

> set(Srcs Main.cu)

> 

> add_executable(${PROJECT_NAME} ${Hdrs} ${Srcs})

> 

> target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

> 

> target_compile_options(${PROJECT_NAME} PRIVATE $<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall -Wextra -pedantic>

>                                                $<$<CXX_COMPILER_ID:MSVC>:/W4>)

> 

> set_target_properties(${PROJECT_NAME} PROPERTIES CUDA_SEPARABLE_COMPILATION ON

>                                                  CUDA_STANDARD 14

>                                                  CUDA_STANDARD_REQUIRED ON

>                                                  CUDA_EXTENSIONS OFF

>                                                  CXX_STANDARD 14

>                                                  CXX_STANDARD_REQUIRED ON

>                                                  CXX_EXTENSIONS OFF)

> 

> source_group ("Headers" FILES ${Hdrs})

> source_group ("Sources" FILES ${Srcs})

> ```

> 

> However, when I compile the code I get the following error:

> 

> [1/3] Building CUDA object CMakeFiles/CUDA_test.dir/Main.cu.o

> FAILED: CMakeFiles/CUDA_test.dir/Main.cu.o

> /usr/bin/nvcc   -I/var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL -g   -Wall -Wextra -pedantic -std=c++14 -x cu -dc /var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL/Main.cu -o CMakeFiles/CUDA_test.dir/Main.cu.o && /usr/bin/nvcc   -I/var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL -g   -Wall -Wextra -pedantic -std=c++14 -x cu -M /var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL/Main.cu -MT CMakeFiles/CUDA_test.dir/Main.cu.o -o CMakeFiles/CUDA_test.dir/Main.cu.o.d

> nvcc fatal   : Unknown option 'Wall'

> ninja: build stopped: subcommand failed.

> 

> CMake seems to pass -Wall -Wextra -pedantic to the device compiler as well, even though it is neither GNU nor Clang, but CUDA. How can I specify warning and similar flags separatly for the host and device compilers?

> --

> 

> Powered by www.kitware.com

> 

> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

> 

> Kitware offers various services to support the CMake community. For more information on each offering, please visit:

> 

> CMake Support: http://cmake.org/cmake/help/support.html

> CMake Consulting: http://cmake.org/cmake/help/consulting.html

> CMake Training Courses: http://cmake.org/cmake/help/training.html

> 

> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

> 

> Follow this link to subscribe/unsubscribe:

> https://cmake.org/mailman/listinfo/cmake

 


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: CUDA language support with host compiler flags

CMake mailing list
In reply to this post by CMake mailing list
Currently to get proper propagation of architecture flags such as
-arch=sm_50,  -compute=compute_X  you need to place these into the
CMAKE_CUDA_FLAGS. This is a known issue, as flags specified by
`target_compile_options` are not propagate to the device linking step,
which needs the correct architecture flags.


On Thu, Feb 28, 2019 at 8:13 AM Máté Ferenc Nagy-Egri
<[hidden email]> wrote:

>
> Hi Robert!
>
>
>
> Thank you for the help. I don’t know if I could’ve find that solution myself. I guess selecting CUDA as the COMPILE_LANGUAGE I can controll .cu compiler options to select architecture and what not.
>
>
>
> Anyhow, if someone needed the minimal template, here it is:
>
>
>
> https://gist.github.com/MathiasMagnus/0edacac888a758fe233cb69f3e291d62
>
>
>
> Cheers,
>
> Máté
>
>
>
> Feladó: Robert Maynard
> Elküldve: 2019. február 27., szerda 15:00
> Címzett: Nagy-Egri MĂĄtĂŠ Ferenc
> Másolatot kap: CMake MailingList
> Tárgy: Re: [CMake] CUDA language support with host compiler flags
>
>
>
> You need to guard the flags with `$<COMPILE_LANGUAGE:CXX>` the
>
> evaluation on a given compiler id is done for all sources of a target,
>
> and not on each target source file.
>
>
>
> So you will need something like:
>
>
>
> set(cxx_flags "$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall
>
> -Wextra -pedantic>
>
>                                                $<$<CXX_COMPILER_ID:MSVC>:/W4")
>
> target_compile_options(${PROJECT_NAME} PRIVATE
>
> $<$<COMPILE_LANGUAGE:CXX>:${cxx_flags}>)
>
>
>
> On Fri, Feb 22, 2019 at 4:11 AM Máté Ferenc Nagy-Egri via CMake
>
> <[hidden email]> wrote:
>
> >
>
> > Hi All!
>
> >
>
> > I am trying to compile CUDA code with controlling both host and device compiler flags.
>
> >
>
> > Currently my CMakeLists.txt looks like:
>
> >
>
> > ```
>
> > cmake_minimum_required(VERSION 3.8) # CUDA language support
>
> >
>
> > project(CUDA_test LANGUAGES CXX CUDA)
>
> >
>
> > if (MSVC)
>
> >   string(REGEX REPLACE "/W[0-9]" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
>
> > endif (MSVC)
>
> >
>
> > set(Hdrs)
>
> >
>
> > set(Srcs Main.cu)
>
> >
>
> > add_executable(${PROJECT_NAME} ${Hdrs} ${Srcs})
>
> >
>
> > target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
>
> >
>
> > target_compile_options(${PROJECT_NAME} PRIVATE $<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall -Wextra -pedantic>
>
> >                                                $<$<CXX_COMPILER_ID:MSVC>:/W4>)
>
> >
>
> > set_target_properties(${PROJECT_NAME} PROPERTIES CUDA_SEPARABLE_COMPILATION ON
>
> >                                                  CUDA_STANDARD 14
>
> >                                                  CUDA_STANDARD_REQUIRED ON
>
> >                                                  CUDA_EXTENSIONS OFF
>
> >                                                  CXX_STANDARD 14
>
> >                                                  CXX_STANDARD_REQUIRED ON
>
> >                                                  CXX_EXTENSIONS OFF)
>
> >
>
> > source_group ("Headers" FILES ${Hdrs})
>
> > source_group ("Sources" FILES ${Srcs})
>
> > ```
>
> >
>
> > However, when I compile the code I get the following error:
>
> >
>
> > [1/3] Building CUDA object CMakeFiles/CUDA_test.dir/Main.cu.o
>
> > FAILED: CMakeFiles/CUDA_test.dir/Main.cu.o
>
> > /usr/bin/nvcc   -I/var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL -g   -Wall -Wextra -pedantic -std=c++14 -x cu -dc /var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL/Main.cu -o CMakeFiles/CUDA_test.dir/Main.cu.o && /usr/bin/nvcc   -I/var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL -g   -Wall -Wextra -pedantic -std=c++14 -x cu -M /var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL/Main.cu -MT CMakeFiles/CUDA_test.dir/Main.cu.o -o CMakeFiles/CUDA_test.dir/Main.cu.o.d
>
> > nvcc fatal   : Unknown option 'Wall'
>
> > ninja: build stopped: subcommand failed.
>
> >
>
> > CMake seems to pass -Wall -Wextra -pedantic to the device compiler as well, even though it is neither GNU nor Clang, but CUDA. How can I specify warning and similar flags separatly for the host and device compilers?
>
> > --
>
> >
>
> > Powered by www.kitware.com
>
> >
>
> > Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> >
>
> > Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
> >
>
> > CMake Support: http://cmake.org/cmake/help/support.html
>
> > CMake Consulting: http://cmake.org/cmake/help/consulting.html
>
> > CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> >
>
> > Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> >
>
> > Follow this link to subscribe/unsubscribe:
>
> > https://cmake.org/mailman/listinfo/cmake
>
>
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake