parse_cubin.cmake 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 (${file_text} MATCHES ".+")
  36. # Remember, four backslashes is escaped to one backslash in the string.
  37. string(REGEX REPLACE ";" "\\\\;" file_text ${file_text})
  38. string(REGEX REPLACE "\ncode" ";code" file_text ${file_text})
  39. list(LENGTH file_text len)
  40. foreach(line ${file_text})
  41. # Only look at "code { }" blocks.
  42. if(line MATCHES "^code")
  43. # Break into individual lines.
  44. string(REGEX REPLACE "\n" ";" line ${line})
  45. foreach(entry ${line})
  46. # Extract kernel names.
  47. if (${entry} MATCHES "[^g]name = ([^ ]+)")
  48. set(entry "${CMAKE_MATCH_1}")
  49. # Check to see if the kernel name starts with "_"
  50. set(skip FALSE)
  51. # if (${entry} MATCHES "^_")
  52. # Skip the rest of this block.
  53. # message("Skipping ${entry}")
  54. # set(skip TRUE)
  55. # else ()
  56. message("Kernel: ${entry}")
  57. # endif ()
  58. endif()
  59. # Skip the rest of the block if necessary
  60. if(NOT skip)
  61. # Registers
  62. if (${entry} MATCHES "reg([ ]+)=([ ]+)([^ ]+)")
  63. set(entry "${CMAKE_MATCH_3}")
  64. message("Registers: ${entry}")
  65. endif()
  66. # Local memory
  67. if (${entry} MATCHES "lmem([ ]+)=([ ]+)([^ ]+)")
  68. set(entry "${CMAKE_MATCH_3}")
  69. message("Local: ${entry}")
  70. endif()
  71. # Shared memory
  72. if (${entry} MATCHES "smem([ ]+)=([ ]+)([^ ]+)")
  73. set(entry "${CMAKE_MATCH_3}")
  74. message("Shared: ${entry}")
  75. endif()
  76. if (${entry} MATCHES "^}")
  77. message("")
  78. endif()
  79. endif()
  80. endforeach()
  81. endif()
  82. endforeach()
  83. else()
  84. # message("FOUND NO DEPENDS")
  85. endif()