/normxcorr/trunk

To get this branch, use:
bzr branch http://suren.me/webbzr/normxcorr/trunk

« back to all changes in this revision

Viewing changes to dict_hw/cmake/run_nvcc.cmake

  • Committer: Suren A. Chilingaryan
  • Date: 2009-12-12 01:38:41 UTC
  • Revision ID: csa@dside.dyndns.org-20091212013841-feih3qa4i28x75j4
Provide stand-alone library

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This file runs the nvcc commands to produce the desired output file along with
 
2
# the dependency file needed by CMake to compute dependencies.  In addition the
 
3
# file checks the output of each command and if the command fails it deletes the
 
4
# output files.
 
5
 
 
6
# Input variables
 
7
#
 
8
# verbose:BOOL=<>          OFF: Be as quiet as possible (default)
 
9
#                          ON : Describe each step
 
10
#
 
11
# build_configuration:STRING=<> Typically one of Debug, MinSizeRel, Release, or
 
12
#                               RelWithDebInfo, but it should match one of the
 
13
#                               entries in CUDA_HOST_FLAGS. This is the build
 
14
#                               configuration used when compiling the code.  If
 
15
#                               blank or unspecified Debug is assumed as this is
 
16
#                               what CMake does.
 
17
#
 
18
# generated_file:STRING=<> File to generate.  This argument must be passed in.
 
19
#
 
20
# generated_cubin_file:STRING=<> File to generate.  This argument must be passed
 
21
#                                                   in if build_cubin is true.
 
22
 
 
23
if(NOT generated_file)
 
24
  message(FATAL_ERROR "You must specify generated_file on the command line")
 
25
endif()
 
26
 
 
27
# Set these up as variables to make reading the generated file easier
 
28
set(CMAKE_COMMAND "@CMAKE_COMMAND@")
 
29
set(source_file "@source_file@")
 
30
set(NVCC_generated_dependency_file "@NVCC_generated_dependency_file@")
 
31
set(cmake_dependency_file "@cmake_dependency_file@")
 
32
set(CUDA_make2cmake "@CUDA_make2cmake@")
 
33
set(CUDA_parse_cubin "@CUDA_parse_cubin@")
 
34
set(build_cubin @build_cubin@)
 
35
# We won't actually use these variables for now, but we need to set this, in
 
36
# order to force this file to be run again if it changes.
 
37
set(generated_file_path "@generated_file_path@")
 
38
set(generated_file_internal "@generated_file@")
 
39
set(generated_cubin_file_internal "@generated_cubin_file@")
 
40
 
 
41
set(CUDA_NVCC_EXECUTABLE "@CUDA_NVCC_EXECUTABLE@")
 
42
set(CUDA_NVCC_FLAGS "@CUDA_NVCC_FLAGS@;@CUDA_WRAP_OPTION_NVCC_FLAGS@")
 
43
@CUDA_NVCC_FLAGS_CONFIG@
 
44
set(nvcc_flags "@nvcc_flags@")
 
45
set(CUDA_NVCC_INCLUDE_ARGS "@CUDA_NVCC_INCLUDE_ARGS@")
 
46
set(format_flag "@format_flag@")
 
47
 
 
48
if(build_cubin AND NOT generated_cubin_file)
 
49
  message(FATAL_ERROR "You must specify generated_cubin_file on the command line")
 
50
endif()
 
51
 
 
52
# This is the list of host compilation flags.  It C or CXX should already have
 
53
# been chosen by FindCUDA.cmake.
 
54
@CUDA_HOST_FLAGS@
 
55
 
 
56
# Take the compiler flags and package them up to be sent to the compiler via -Xcompiler
 
57
set(nvcc_host_compiler_flags "")
 
58
# If we weren't given a build_configuration, use Debug.
 
59
if(NOT build_configuration)
 
60
  set(build_configuration Debug)
 
61
endif()
 
62
string(TOUPPER "${build_configuration}" build_configuration)
 
63
#message("CUDA_NVCC_HOST_COMPILER_FLAGS = ${CUDA_NVCC_HOST_COMPILER_FLAGS}")
 
64
foreach(flag ${CMAKE_HOST_FLAGS} ${CMAKE_HOST_FLAGS_${build_configuration}})
 
65
  # Extra quotes are added around each flag to help nvcc parse out flags with spaces.
 
66
  set(nvcc_host_compiler_flags "${nvcc_host_compiler_flags},\"${flag}\"")
 
67
endforeach()
 
68
if (nvcc_host_compiler_flags)
 
69
  set(nvcc_host_compiler_flags "-Xcompiler" ${nvcc_host_compiler_flags})
 
70
endif()
 
71
#message("nvcc_host_compiler_flags = \"${nvcc_host_compiler_flags}\"")
 
72
# Add the build specific configuration flags
 
73
list(APPEND CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS_${build_configuration}})
 
74
 
 
75
if(DEFINED CCBIN)
 
76
  set(CCBIN -ccbin "${CCBIN}")
 
77
endif()
 
78
 
 
79
# cuda_execute_process - Executes a command with optional command echo and status message.
 
80
#
 
81
#   status  - Status message to print if verbose is true
 
82
#   command - COMMAND argument from the usual execute_process argument structure
 
83
#   ARGN    - Remaining arguments are the command with arguments
 
84
#
 
85
#   CUDA_result - return value from running the command
 
86
#
 
87
# Make this a macro instead of a function, so that things like RESULT_VARIABLE
 
88
# and other return variables are present after executing the process.
 
89
macro(cuda_execute_process status command)
 
90
  set(_command ${command})
 
91
  if(NOT _command STREQUAL "COMMAND")
 
92
    message(FATAL_ERROR "Malformed call to cuda_execute_process.  Missing COMMAND as second argument. (command = ${command})")
 
93
  endif()
 
94
  if(verbose)
 
95
    execute_process(COMMAND "${CMAKE_COMMAND}" -E echo -- ${status})
 
96
    # Now we need to build up our command string.  We are accounting for quotes
 
97
    # and spaces, anything else is left up to the user to fix if they want to
 
98
    # copy and paste a runnable command line.
 
99
    set(cuda_execute_process_string)
 
100
    foreach(arg ${ARGN})
 
101
      # If there are quotes, excape them, so they come through.
 
102
      string(REPLACE "\"" "\\\"" arg ${arg})
 
103
      # Args with spaces need quotes around them to get them to be parsed as a single argument.
 
104
      if(arg MATCHES " ")
 
105
        list(APPEND cuda_execute_process_string "\"${arg}\"")
 
106
      else()
 
107
        list(APPEND cuda_execute_process_string ${arg})
 
108
      endif()
 
109
    endforeach()
 
110
    # Echo the command
 
111
    execute_process(COMMAND ${CMAKE_COMMAND} -E echo ${cuda_execute_process_string})
 
112
  endif(verbose)
 
113
  # Run the command
 
114
  execute_process(COMMAND ${ARGN} RESULT_VARIABLE CUDA_result )
 
115
endmacro()
 
116
 
 
117
# Delete the target file
 
118
cuda_execute_process(
 
119
  "Removing ${generated_file}"
 
120
  COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}"
 
121
  )
 
122
 
 
123
# Generate the dependency file
 
124
cuda_execute_process(
 
125
  "Generating dependency file: ${NVCC_generated_dependency_file}"
 
126
  COMMAND "${CUDA_NVCC_EXECUTABLE}"
 
127
  "${source_file}"
 
128
  ${CUDA_NVCC_FLAGS}
 
129
  ${nvcc_flags}
 
130
  ${CCBIN}
 
131
  ${nvcc_host_compiler_flags}
 
132
  -DNVCC
 
133
  -M
 
134
  -o "${NVCC_generated_dependency_file}"
 
135
  ${CUDA_NVCC_INCLUDE_ARGS}
 
136
  )
 
137
 
 
138
if(CUDA_result)
 
139
  message(FATAL_ERROR "Error generating ${generated_file}")
 
140
endif()
 
141
 
 
142
# Generate the cmake readable dependency file to a temp file.  Don't put the
 
143
# quotes just around the filenames for the input_file and output_file variables.
 
144
# CMake will pass the quotes through and not be able to find the file.
 
145
cuda_execute_process(
 
146
  "Generating temporary cmake readable file: ${cmake_dependency_file}.tmp"
 
147
  COMMAND "${CMAKE_COMMAND}"
 
148
  -D "input_file:FILEPATH=${NVCC_generated_dependency_file}"
 
149
  -D "output_file:FILEPATH=${cmake_dependency_file}.tmp"
 
150
  -P "${CUDA_make2cmake}"
 
151
  )
 
152
 
 
153
if(CUDA_result)
 
154
  message(FATAL_ERROR "Error generating ${generated_file}")
 
155
endif()
 
156
 
 
157
# Copy the file if it is different
 
158
cuda_execute_process(
 
159
  "Copy if different ${cmake_dependency_file}.tmp to ${cmake_dependency_file}"
 
160
  COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${cmake_dependency_file}.tmp" "${cmake_dependency_file}"
 
161
  )
 
162
 
 
163
if(CUDA_result)
 
164
  message(FATAL_ERROR "Error generating ${generated_file}")
 
165
endif()
 
166
 
 
167
# Delete the temporary file
 
168
cuda_execute_process(
 
169
  "Removing ${cmake_dependency_file}.tmp and ${NVCC_generated_dependency_file}"
 
170
  COMMAND "${CMAKE_COMMAND}" -E remove "${cmake_dependency_file}.tmp" "${NVCC_generated_dependency_file}"
 
171
  )
 
172
 
 
173
if(CUDA_result)
 
174
  message(FATAL_ERROR "Error generating ${generated_file}")
 
175
endif()
 
176
 
 
177
# Generate the code
 
178
cuda_execute_process(
 
179
  "Generating ${generated_file}"
 
180
  COMMAND "${CUDA_NVCC_EXECUTABLE}"
 
181
  "${source_file}"
 
182
  ${CUDA_NVCC_FLAGS}
 
183
  ${nvcc_flags}
 
184
  ${CCBIN}
 
185
  ${nvcc_host_compiler_flags}
 
186
  -DNVCC
 
187
  ${format_flag} -o "${generated_file}"
 
188
  ${CUDA_NVCC_INCLUDE_ARGS}
 
189
  )
 
190
 
 
191
if(CUDA_result)
 
192
  # Since nvcc can sometimes leave half done files make sure that we delete the output file.
 
193
  cuda_execute_process(
 
194
    "Removing ${generated_file}"
 
195
    COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}"
 
196
    )
 
197
  message(FATAL_ERROR "Error generating file ${generated_file}")
 
198
else()
 
199
  message("Generated ${generated_file} successfully.")
 
200
endif()
 
201
 
 
202
# Cubin resource report commands.
 
203
if( build_cubin )
 
204
  # Run with -cubin to produce resource usage report.
 
205
  cuda_execute_process(
 
206
    "Generating ${generated_cubin_file}"
 
207
    COMMAND "${CUDA_NVCC_EXECUTABLE}"
 
208
    "${source_file}"
 
209
    ${CUDA_NVCC_FLAGS}
 
210
    ${nvcc_flags}
 
211
    ${CCBIN}
 
212
    ${nvcc_host_compiler_flags}
 
213
    -DNVCC
 
214
    -cubin
 
215
    -o "${generated_cubin_file}"
 
216
    ${CUDA_NVCC_INCLUDE_ARGS}
 
217
    )
 
218
 
 
219
  # Execute the parser script.
 
220
  cuda_execute_process(
 
221
    "Executing the parser script"
 
222
    COMMAND  "${CMAKE_COMMAND}"
 
223
    -D "input_file:STRING=${generated_cubin_file}"
 
224
    -P "${CUDA_parse_cubin}"
 
225
    )
 
226
 
 
227
endif( build_cubin )