parse_cubin.cmake 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # James Bigler, NVIDIA Corp (nvidia.com - jbigler)
  2. # Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
  3. #
  4. # Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
  5. #
  6. # Copyright (c) 2007-2009
  7. # Scientific Computing and Imaging Institute, University of Utah
  8. #
  9. # This code is licensed under the MIT License. See the FindCUDA.cmake script
  10. # for the text of the license.
  11. # The MIT License
  12. #
  13. # License for the specific language governing rights and limitations under
  14. # Permission is hereby granted, free of charge, to any person obtaining a
  15. # copy of this software and associated documentation files (the "Software"),
  16. # to deal in the Software without restriction, including without limitation
  17. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  18. # and/or sell copies of the Software, and to permit persons to whom the
  19. # Software is furnished to do so, subject to the following conditions:
  20. #
  21. # The above copyright notice and this permission notice shall be included
  22. # in all copies or substantial portions of the Software.
  23. #
  24. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  25. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  27. # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  29. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  30. # DEALINGS IN THE SOFTWARE.
  31. #
  32. #######################################################################
  33. # Parses a .cubin file produced by nvcc and reports statistics about the file.
  34. file(READ ${input_file} file_text)
  35. if (NOT "${file_text}" STREQUAL "")
  36. string(REPLACE ";" "\\;" file_text ${file_text})
  37. string(REPLACE "\ncode" ";code" file_text ${file_text})
  38. list(LENGTH file_text len)
  39. foreach(line ${file_text})
  40. # Only look at "code { }" blocks.
  41. if(line MATCHES "^code")
  42. # Break into individual lines.
  43. string(REGEX REPLACE "\n" ";" line ${line})
  44. foreach(entry ${line})
  45. # Extract kernel names.
  46. if (${entry} MATCHES "[^g]name = ([^ ]+)")
  47. set(entry "${CMAKE_MATCH_1}")
  48. # Check to see if the kernel name starts with "_"
  49. set(skip FALSE)
  50. # if (${entry} MATCHES "^_")
  51. # Skip the rest of this block.
  52. # message("Skipping ${entry}")
  53. # set(skip TRUE)
  54. # else ()
  55. message("Kernel: ${entry}")
  56. # endif ()
  57. endif()
  58. # Skip the rest of the block if necessary
  59. if(NOT skip)
  60. # Registers
  61. if (${entry} MATCHES "reg([ ]+)=([ ]+)([^ ]+)")
  62. set(entry "${CMAKE_MATCH_3}")
  63. message("Registers: ${entry}")
  64. endif()
  65. # Local memory
  66. if (${entry} MATCHES "lmem([ ]+)=([ ]+)([^ ]+)")
  67. set(entry "${CMAKE_MATCH_3}")
  68. message("Local: ${entry}")
  69. endif()
  70. # Shared memory
  71. if (${entry} MATCHES "smem([ ]+)=([ ]+)([^ ]+)")
  72. set(entry "${CMAKE_MATCH_3}")
  73. message("Shared: ${entry}")
  74. endif()
  75. if (${entry} MATCHES "^}")
  76. message("")
  77. endif()
  78. endif()
  79. endforeach()
  80. endif()
  81. endforeach()
  82. else()
  83. # message("FOUND NO DEPENDS")
  84. endif()