Howto pass flag to nvcc compiler in CMAKE












0














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 ?










share|improve this question




















  • 1




    I think you are looking for target_compile_options, not add_compile_options.
    – havogt
    Nov 12 '18 at 21:46












  • target_compile_options(myprog PUBLIC $<$<COMPILE_LANGUAGE:CUDA>:--ptxas-options=-v>) worked. Thank you.
    – Nouman Tajik
    Nov 13 '18 at 4:02
















0














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 ?










share|improve this question




















  • 1




    I think you are looking for target_compile_options, not add_compile_options.
    – havogt
    Nov 12 '18 at 21:46












  • target_compile_options(myprog PUBLIC $<$<COMPILE_LANGUAGE:CUDA>:--ptxas-options=-v>) worked. Thank you.
    – Nouman Tajik
    Nov 13 '18 at 4:02














0












0








0







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 ?










share|improve this question















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 ?







cmake cuda nvcc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 10:52

























asked Nov 12 '18 at 5:33









Nouman Tajik

319




319








  • 1




    I think you are looking for target_compile_options, not add_compile_options.
    – havogt
    Nov 12 '18 at 21:46












  • target_compile_options(myprog PUBLIC $<$<COMPILE_LANGUAGE:CUDA>:--ptxas-options=-v>) worked. Thank you.
    – Nouman Tajik
    Nov 13 '18 at 4:02














  • 1




    I think you are looking for target_compile_options, not add_compile_options.
    – havogt
    Nov 12 '18 at 21:46












  • target_compile_options(myprog PUBLIC $<$<COMPILE_LANGUAGE:CUDA>:--ptxas-options=-v>) worked. Thank you.
    – Nouman Tajik
    Nov 13 '18 at 4:02








1




1




I think you are looking for target_compile_options, not add_compile_options.
– havogt
Nov 12 '18 at 21:46






I think you are looking for target_compile_options, not add_compile_options.
– havogt
Nov 12 '18 at 21:46














target_compile_options(myprog PUBLIC $<$<COMPILE_LANGUAGE:CUDA>:--ptxas-options=-v>) worked. Thank you.
– Nouman Tajik
Nov 13 '18 at 4:02




target_compile_options(myprog PUBLIC $<$<COMPILE_LANGUAGE:CUDA>:--ptxas-options=-v>) worked. Thank you.
– Nouman Tajik
Nov 13 '18 at 4:02












3 Answers
3






active

oldest

votes


















3














The newer approach of cmake cuda sets some other variables. Check the docs here.



What we need is to set CMAKE_<LANG>_FLAGS, which actually CMAKE_CUDA_FLAGS here.



set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --ptxas-options=-v")





share|improve this answer































    2














    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.






    share|improve this answer





























      -1














      How about?...



      find_package( CUDA REQUIRED )
      set( CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}" "--ptxas-options=-v" )

      include_directories( ${CUDA_INCLUDE_DIRS} )
      cuda_add_library( kernel_lib ${sources} )


      You can check also the CMake CUDA documentation online... https://cmake.org/cmake/help/latest/module/FindCUDA.html






      share|improve this answer























      • Tried that but didn't worked.
        – Nouman Tajik
        Nov 12 '18 at 8:54










      • Make sure you are compiling with the cuda__add ... target commands.
        – KlingonJoe
        Nov 12 '18 at 9:39










      • You should also think about breaking up your CMakeLists.txt file. You have a lot of stuff in there. Consider sending some stuff to /config directory, and adding subdirectory - separating the C and CUDA code into separate directories is a good idea here.
        – KlingonJoe
        Nov 12 '18 at 9:46






      • 1




        I downvoted as the modern way is using the built-in CUDA language support, which the OP already uses.
        – havogt
        Nov 12 '18 at 21:36











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256405%2fhowto-pass-flag-to-nvcc-compiler-in-cmake%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      The newer approach of cmake cuda sets some other variables. Check the docs here.



      What we need is to set CMAKE_<LANG>_FLAGS, which actually CMAKE_CUDA_FLAGS here.



      set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --ptxas-options=-v")





      share|improve this answer




























        3














        The newer approach of cmake cuda sets some other variables. Check the docs here.



        What we need is to set CMAKE_<LANG>_FLAGS, which actually CMAKE_CUDA_FLAGS here.



        set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --ptxas-options=-v")





        share|improve this answer


























          3












          3








          3






          The newer approach of cmake cuda sets some other variables. Check the docs here.



          What we need is to set CMAKE_<LANG>_FLAGS, which actually CMAKE_CUDA_FLAGS here.



          set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --ptxas-options=-v")





          share|improve this answer














          The newer approach of cmake cuda sets some other variables. Check the docs here.



          What we need is to set CMAKE_<LANG>_FLAGS, which actually CMAKE_CUDA_FLAGS here.



          set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --ptxas-options=-v")






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 19 '18 at 5:47

























          answered Nov 13 '18 at 8:50









          halfelf

          6,46993146




          6,46993146

























              2














              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.






              share|improve this answer


























                2














                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.






                share|improve this answer
























                  2












                  2








                  2






                  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.






                  share|improve this answer












                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 15 '18 at 9:05









                  havogt

                  1,53011321




                  1,53011321























                      -1














                      How about?...



                      find_package( CUDA REQUIRED )
                      set( CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}" "--ptxas-options=-v" )

                      include_directories( ${CUDA_INCLUDE_DIRS} )
                      cuda_add_library( kernel_lib ${sources} )


                      You can check also the CMake CUDA documentation online... https://cmake.org/cmake/help/latest/module/FindCUDA.html






                      share|improve this answer























                      • Tried that but didn't worked.
                        – Nouman Tajik
                        Nov 12 '18 at 8:54










                      • Make sure you are compiling with the cuda__add ... target commands.
                        – KlingonJoe
                        Nov 12 '18 at 9:39










                      • You should also think about breaking up your CMakeLists.txt file. You have a lot of stuff in there. Consider sending some stuff to /config directory, and adding subdirectory - separating the C and CUDA code into separate directories is a good idea here.
                        – KlingonJoe
                        Nov 12 '18 at 9:46






                      • 1




                        I downvoted as the modern way is using the built-in CUDA language support, which the OP already uses.
                        – havogt
                        Nov 12 '18 at 21:36
















                      -1














                      How about?...



                      find_package( CUDA REQUIRED )
                      set( CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}" "--ptxas-options=-v" )

                      include_directories( ${CUDA_INCLUDE_DIRS} )
                      cuda_add_library( kernel_lib ${sources} )


                      You can check also the CMake CUDA documentation online... https://cmake.org/cmake/help/latest/module/FindCUDA.html






                      share|improve this answer























                      • Tried that but didn't worked.
                        – Nouman Tajik
                        Nov 12 '18 at 8:54










                      • Make sure you are compiling with the cuda__add ... target commands.
                        – KlingonJoe
                        Nov 12 '18 at 9:39










                      • You should also think about breaking up your CMakeLists.txt file. You have a lot of stuff in there. Consider sending some stuff to /config directory, and adding subdirectory - separating the C and CUDA code into separate directories is a good idea here.
                        – KlingonJoe
                        Nov 12 '18 at 9:46






                      • 1




                        I downvoted as the modern way is using the built-in CUDA language support, which the OP already uses.
                        – havogt
                        Nov 12 '18 at 21:36














                      -1












                      -1








                      -1






                      How about?...



                      find_package( CUDA REQUIRED )
                      set( CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}" "--ptxas-options=-v" )

                      include_directories( ${CUDA_INCLUDE_DIRS} )
                      cuda_add_library( kernel_lib ${sources} )


                      You can check also the CMake CUDA documentation online... https://cmake.org/cmake/help/latest/module/FindCUDA.html






                      share|improve this answer














                      How about?...



                      find_package( CUDA REQUIRED )
                      set( CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}" "--ptxas-options=-v" )

                      include_directories( ${CUDA_INCLUDE_DIRS} )
                      cuda_add_library( kernel_lib ${sources} )


                      You can check also the CMake CUDA documentation online... https://cmake.org/cmake/help/latest/module/FindCUDA.html







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Nov 13 '18 at 4:54

























                      answered Nov 12 '18 at 8:31









                      KlingonJoe

                      508414




                      508414












                      • Tried that but didn't worked.
                        – Nouman Tajik
                        Nov 12 '18 at 8:54










                      • Make sure you are compiling with the cuda__add ... target commands.
                        – KlingonJoe
                        Nov 12 '18 at 9:39










                      • You should also think about breaking up your CMakeLists.txt file. You have a lot of stuff in there. Consider sending some stuff to /config directory, and adding subdirectory - separating the C and CUDA code into separate directories is a good idea here.
                        – KlingonJoe
                        Nov 12 '18 at 9:46






                      • 1




                        I downvoted as the modern way is using the built-in CUDA language support, which the OP already uses.
                        – havogt
                        Nov 12 '18 at 21:36


















                      • Tried that but didn't worked.
                        – Nouman Tajik
                        Nov 12 '18 at 8:54










                      • Make sure you are compiling with the cuda__add ... target commands.
                        – KlingonJoe
                        Nov 12 '18 at 9:39










                      • You should also think about breaking up your CMakeLists.txt file. You have a lot of stuff in there. Consider sending some stuff to /config directory, and adding subdirectory - separating the C and CUDA code into separate directories is a good idea here.
                        – KlingonJoe
                        Nov 12 '18 at 9:46






                      • 1




                        I downvoted as the modern way is using the built-in CUDA language support, which the OP already uses.
                        – havogt
                        Nov 12 '18 at 21:36
















                      Tried that but didn't worked.
                      – Nouman Tajik
                      Nov 12 '18 at 8:54




                      Tried that but didn't worked.
                      – Nouman Tajik
                      Nov 12 '18 at 8:54












                      Make sure you are compiling with the cuda__add ... target commands.
                      – KlingonJoe
                      Nov 12 '18 at 9:39




                      Make sure you are compiling with the cuda__add ... target commands.
                      – KlingonJoe
                      Nov 12 '18 at 9:39












                      You should also think about breaking up your CMakeLists.txt file. You have a lot of stuff in there. Consider sending some stuff to /config directory, and adding subdirectory - separating the C and CUDA code into separate directories is a good idea here.
                      – KlingonJoe
                      Nov 12 '18 at 9:46




                      You should also think about breaking up your CMakeLists.txt file. You have a lot of stuff in there. Consider sending some stuff to /config directory, and adding subdirectory - separating the C and CUDA code into separate directories is a good idea here.
                      – KlingonJoe
                      Nov 12 '18 at 9:46




                      1




                      1




                      I downvoted as the modern way is using the built-in CUDA language support, which the OP already uses.
                      – havogt
                      Nov 12 '18 at 21:36




                      I downvoted as the modern way is using the built-in CUDA language support, which the OP already uses.
                      – havogt
                      Nov 12 '18 at 21:36


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256405%2fhowto-pass-flag-to-nvcc-compiler-in-cmake%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      Tangent Lines Diagram Along Smooth Curve

                      Yusuf al-Mu'taman ibn Hud

                      Zucchini