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
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#######################################################################
35# Parses a .cubin file produced by nvcc and reports statistics about the file.
36
37
38file(READ ${input_file} file_text)
39
40if (NOT "${file_text}" STREQUAL "")
41
42  string(REPLACE ";" "\\;" file_text ${file_text})
43  string(REPLACE "\ncode" ";code" file_text ${file_text})
44
45  list(LENGTH file_text len)
46
47  foreach(line ${file_text})
48
49    # Only look at "code { }" blocks.
50    if(line MATCHES "^code")
51
52      # Break into individual lines.
53      string(REGEX REPLACE "\n" ";" line ${line})
54
55      foreach(entry ${line})
56
57        # Extract kernel names.
58        if (${entry} MATCHES "[^g]name = ([^ ]+)")
59          set(entry "${CMAKE_MATCH_1}")
60
61          # Check to see if the kernel name starts with "_"
62          set(skip FALSE)
63          # if (${entry} MATCHES "^_")
64            # Skip the rest of this block.
65            # message("Skipping ${entry}")
66            # set(skip TRUE)
67          # else ()
68            message("Kernel:    ${entry}")
69          # endif ()
70
71        endif()
72
73        # Skip the rest of the block if necessary
74        if(NOT skip)
75
76          # Registers
77          if (${entry} MATCHES "reg([ ]+)=([ ]+)([^ ]+)")
78            set(entry "${CMAKE_MATCH_3}")
79            message("Registers: ${entry}")
80          endif()
81
82          # Local memory
83          if (${entry} MATCHES "lmem([ ]+)=([ ]+)([^ ]+)")
84            set(entry "${CMAKE_MATCH_3}")
85            message("Local:     ${entry}")
86          endif()
87
88          # Shared memory
89          if (${entry} MATCHES "smem([ ]+)=([ ]+)([^ ]+)")
90            set(entry "${CMAKE_MATCH_3}")
91            message("Shared:    ${entry}")
92          endif()
93
94          if (${entry} MATCHES "^}")
95            message("")
96          endif()
97
98        endif()
99
100
101      endforeach()
102
103    endif()
104
105  endforeach()
106
107else()
108  # message("FOUND NO DEPENDS")
109endif()
110