compiling .cpp/.cxx with CUDA compiler

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

compiling .cpp/.cxx with CUDA compiler

Kai Germaschewski
For background, a bunch of projects help writing portable C++ code that can be compiled into CUDA device code as one option, e.g. hemi, kokkos, RAJA (https://devblogs.nvidia.com/simple-portable-parallel-c-hemi-2/). As a consequence, if available those source files need to be compiled with the CUDA compiler, but with the regular C++ compiler otherwise.

I'm wondering whether there is a clean way to support this in a cmake build. Renaming my source files to `.cu` is bad if I'm on the system without CUDA. I figured out that I can set the LANGUAGE property on a given .cpp/.cxx source file to CUDA to have it compiled with CMAKE_CUDA_COMPILER, but that's quite a hassle to do for every source file. Kokkos instead creates a `nvcc_wrapper` script which one is supposed to use as CMAKE_CXX_COMPILER, but that definitely seems like a kludge to me (and giving me troubles).

Things would probably be much better for me if there was a way to change the default language for .cxx / .cpp extensions. Is there a way to do this?

--Kai




--

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: compiling .cpp/.cxx with CUDA compiler

Robert Maynard
In general I go with the source property approach, since you can pass
it a collection of files to be marked as CUDA.
If you are aware of when all sources have been added to a target you
can easily mark them all as cuda with:

get_target_property(source_files <target> SOURCES)
set_source_files_properties(${source_files} PROPERTIES LANGUAGE CUDA)

As far as changing the mapping of file extensions to languages, as far
as I am aware that is currently unsupported.

On Tue, Jul 2, 2019 at 2:19 PM Kai Germaschewski
<[hidden email]> wrote:

>
> For background, a bunch of projects help writing portable C++ code that can be compiled into CUDA device code as one option, e.g. hemi, kokkos, RAJA (https://devblogs.nvidia.com/simple-portable-parallel-c-hemi-2/). As a consequence, if available those source files need to be compiled with the CUDA compiler, but with the regular C++ compiler otherwise.
>
> I'm wondering whether there is a clean way to support this in a cmake build. Renaming my source files to `.cu` is bad if I'm on the system without CUDA. I figured out that I can set the LANGUAGE property on a given .cpp/.cxx source file to CUDA to have it compiled with CMAKE_CUDA_COMPILER, but that's quite a hassle to do for every source file. Kokkos instead creates a `nvcc_wrapper` script which one is supposed to use as CMAKE_CXX_COMPILER, but that definitely seems like a kludge to me (and giving me troubles).
>
> Things would probably be much better for me if there was a way to change the default language for .cxx / .cpp extensions. Is there a way to do this?
>
> --Kai
>
>
>
> --
>
> 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: compiling .cpp/.cxx with CUDA compiler

Dmitry Mikushin-2
In reply to this post by Kai Germaschewski
Compiling C++ code with CUDA compiler practically means only to implicitly include a bunch of CUDA-specific headers like cuda_runtime_api.h. Other than that, it's the same as compiling with the host C++ compiler. Thus, you can get the desired behavior by explicitly including those headers in case of C++-compilation and letting CMake include_directories to know where to search for them.

Kind regards,
- Dmitry.


вт, 2 июл. 2019 г. в 20:19, Kai Germaschewski <[hidden email]>:
For background, a bunch of projects help writing portable C++ code that can be compiled into CUDA device code as one option, e.g. hemi, kokkos, RAJA (https://devblogs.nvidia.com/simple-portable-parallel-c-hemi-2/). As a consequence, if available those source files need to be compiled with the CUDA compiler, but with the regular C++ compiler otherwise.

I'm wondering whether there is a clean way to support this in a cmake build. Renaming my source files to `.cu` is bad if I'm on the system without CUDA. I figured out that I can set the LANGUAGE property on a given .cpp/.cxx source file to CUDA to have it compiled with CMAKE_CUDA_COMPILER, but that's quite a hassle to do for every source file. Kokkos instead creates a `nvcc_wrapper` script which one is supposed to use as CMAKE_CXX_COMPILER, but that definitely seems like a kludge to me (and giving me troubles).

Things would probably be much better for me if there was a way to change the default language for .cxx / .cpp extensions. Is there a way to do this?

--Kai



--

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: compiling .cpp/.cxx with CUDA compiler

Kai Germaschewski
In reply to this post by Robert Maynard

On Tue, Jul 2, 2019 at 2:48 PM Robert Maynard <[hidden email]> wrote:
get_target_property(source_files <target> SOURCES)
set_source_files_properties(${source_files} PROPERTIES LANGUAGE CUDA)

Thanks, that'll work for the time being, I can put this into a function/macro and it'll look alright.

--Kai
 

--

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: compiling .cpp/.cxx with CUDA compiler

Kai Germaschewski
Thank. Yeah, I've seen BLT through it's use in RAJA. You're right, it'd work, but I'm reluctant to stray away from "vanilla" cmake too much, since other people will have to deal with this code, and cmake itself is already quite a step up from the regular Makefiles that they're used to.

--Kai


On Tue, Jul 2, 2019 at 4:14 PM David Poliakoff <[hidden email]> wrote:
Kai,

If you're game to use a framework, back at LLNL I used a CMake system called BLT a lot (https://github.com/LLNL/blt ). I believe it uses something similar to what you've been recommended (get_target_property, set_source_files_properties), but it has a mechanism where you say targets "depend on" things, and if a target "depends_on" CUDA it uses the CUDA compiler (and behaves similarly for MPI).

I know frameworks are a big shift, but it always saved me more effort than it cost me in similar problems, and if you're looking at things like RAJA and Kokkos it's probably going to be up your alley.

Best,

David P

Opinions in this email are my own, not those of my employer

On Tue, Jul 2, 2019 at 12:44 PM Kai Germaschewski <[hidden email]> wrote:

On Tue, Jul 2, 2019 at 2:48 PM Robert Maynard <[hidden email]> wrote:
get_target_property(source_files <target> SOURCES)
set_source_files_properties(${source_files} PROPERTIES LANGUAGE CUDA)

Thanks, that'll work for the time being, I can put this into a function/macro and it'll look alright.

--Kai
 
--

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


--
Thanks,

David

--

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