Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
872 views
in Technique[技术] by (71.8m points)

cuda - Howto pass flag to nvcc compiler in CMAKE

I have a C project in Cmake in which I have embedded cuda kernel module.

I want to pass --ptxas-options=-v only to nvcc in-order to view Number of registers usage per thread and shared Memory usage per block.

By searching on howto pass flags to nvcc in Cmake, I came across a solution

add_compile_options(myprog
    PRIVATE
    $<$<COMPILE_LANGUAGE:C>:-Wall>
    $<$<COMPILE_LANGUAGE:CUDA>:-arch=sm_20 -ptxas-options=-v>
)

but this didn't show me the above properties. I think these flags aren't passed to nvcc properly.

How can I pass --ptxas-options=-v to my nvcc compiler ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The proper way to set CUDA flags only on a target is

target_compile_options(<my_target> PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:my_cuda_option>) 

This will set the option, via the generator expression, only for files which are compiled for the CUDA language.

Using CMAKE_CUDA_FLAGS as suggested by the other answer sets a global property for all targets, which might or might not be the right approach depending on the use-case.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...