parse_cubin.cmake 3.58 KB
Newer Older
1
#  For more information, please see: http://software.sci.utah.edu
2
#
3
#  The MIT License
4
#
5
#  Copyright (c) 2007
6
7
#  Scientific Computing and Imaging Institute, University of Utah
#
8
9
10
11
12
13
14
#  License for the specific language governing rights and limitations under
#  Permission is hereby granted, free of charge, to any person obtaining a
#  copy of this software and associated documentation files (the "Software"),
#  to deal in the Software without restriction, including without limitation
#  the rights to use, copy, modify, merge, publish, distribute, sublicense,
#  and/or sell copies of the Software, and to permit persons to whom the
#  Software is furnished to do so, subject to the following conditions:
15
#
16
17
#  The above copyright notice and this permission notice shall be included
#  in all copies or substantial portions of the Software.
18
#
19
20
21
22
23
24
25
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
#  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
#  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
#  DEALINGS IN THE SOFTWARE.
26

27
28
29
# .cubin Parsing CMake Script
# Abe Stephens
# (c) 2007 Scientific Computing and Imaging Institute, University of Utah
30

31
FILE(READ ${input_file} file_text)
32

33
IF (${file_text} MATCHES ".+")
34
35

  # Remember, four backslashes is escaped to one backslash in the string.
36
37
38
39
  STRING(REGEX REPLACE ";" "\\\\;" file_text ${file_text})
  STRING(REGEX REPLACE "\ncode" ";code" file_text ${file_text})
  
  LIST(LENGTH file_text len)
40

41
  FOREACH(line ${file_text})
42
43

    # Only look at "code { }" blocks.
44
45
    IF(line MATCHES "^code")
      
46
      # Break into individual lines.
47
      STRING(REGEX REPLACE "\n" ";" line ${line})
48

49
      FOREACH(entry ${line})
50
51

        # Extract kernel names.
52
53
        IF (${entry} MATCHES "[^g]name = ([^ ]+)")
          STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
54
55

          # Check to see if the kernel name starts with "_"
56
57
          SET(skip FALSE)
          # IF (${entry} MATCHES "^_")
58
            # Skip the rest of this block.
59
60
61
62
63
            # MESSAGE("Skipping ${entry}")
            # SET(skip TRUE)
          # ELSE (${entry} MATCHES "^_")
            MESSAGE("Kernel:    ${entry}")  
          # ENDIF (${entry} MATCHES "^_")
64

65
        ENDIF(${entry} MATCHES "[^g]name = ([^ ]+)")
66
67

        # Skip the rest of the block if necessary
68
        IF(NOT skip)
69
70

          # Registers
71
72
73
74
75
          IF (${entry} MATCHES "reg = ([^ ]+)")
            STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
            MESSAGE("Registers: ${entry}")
          ENDIF(${entry} MATCHES "reg = ([^ ]+)")
          
76
          # Local memory
77
78
79
80
81
          IF (${entry} MATCHES "lmem = ([^ ]+)")
            STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
            MESSAGE("Local:     ${entry}")
          ENDIF(${entry} MATCHES "lmem = ([^ ]+)")
          
82
          # Shared memory
83
84
85
86
87
88
89
90
          IF (${entry} MATCHES "smem = ([^ ]+)")
            STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
            MESSAGE("Shared:    ${entry}")
          ENDIF(${entry} MATCHES "smem = ([^ ]+)")
                  
          IF (${entry} MATCHES "^}")
            MESSAGE("")
          ENDIF(${entry} MATCHES "^}")
91

92
        ENDIF(NOT skip)
93
94


95
      ENDFOREACH(entry)
96

97
    ENDIF(line MATCHES "^code")
98

99
  ENDFOREACH(line) 
100

101
102
103
ELSE(${file_text} MATCHES ".+") 
  # MESSAGE("FOUND NO DEPENDS")
ENDIF(${file_text} MATCHES ".+")
104
105