parse_cubin.cmake 3.7 KB

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