parse_cubin.cmake 3.4 KB

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