Skip to content

Commit bcaea3a

Browse files
committed
Fix bin2cpp null termination
It was affecting ptx files as they were failing to compile. CUDA cuLinkAddData requires the string to be NULL Terminated.
1 parent 3d0b3f2 commit bcaea3a

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

CMakeModules/CLKernelToH.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ include(CMakeParseArguments)
2828
set(BIN2CPP_PROGRAM "bin2cpp")
2929

3030
function(CL_KERNEL_TO_H)
31-
cmake_parse_arguments(RTCS "" "VARNAME;EXTENSION;OUTPUT_DIR;TARGETS;NAMESPACE;BINARY;EOF" "SOURCES" ${ARGN})
31+
cmake_parse_arguments(RTCS "" "VARNAME;EXTENSION;OUTPUT_DIR;TARGETS;NAMESPACE;BINARY;NULLTERM" "SOURCES" ${ARGN})
3232

3333
set(_output_files "")
3434
foreach(_input_file ${RTCS_SOURCES})
@@ -42,6 +42,9 @@ function(CL_KERNEL_TO_H)
4242
if(${RTCS_BINARY})
4343
set(_binary "--binary")
4444
endif(${RTCS_BINARY})
45+
if(${RTCS_NULLTERM})
46+
set(_nullterm "--nullterm")
47+
endif(${RTCS_NULLTERM})
4548

4649
string(REPLACE "." "_" var_name ${var_name})
4750

@@ -53,7 +56,7 @@ function(CL_KERNEL_TO_H)
5356
DEPENDS ${_input_file} ${BIN2CPP_PROGRAM}
5457
COMMAND ${CMAKE_COMMAND} -E make_directory "${_output_path}"
5558
COMMAND ${CMAKE_COMMAND} -E echo "\\#include \\<${_path}/${_name_we}.hpp\\>" >>"${_output_file}"
56-
COMMAND ${BIN2CPP_PROGRAM} --file ${_name} --namespace ${_namespace} --output ${_output_file} --name ${var_name} ${_binary} --eof ${RTCS_EOF}
59+
COMMAND ${BIN2CPP_PROGRAM} --file ${_name} --namespace ${_namespace} --output ${_output_file} --name ${var_name} ${_binary} ${_nullterm}
5760
WORKING_DIRECTORY "${_path}"
5861
COMMENT "Compiling ${_input_file} to C++ source"
5962
)

CMakeModules/bin2cpp.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ xxd but adds support for namespaces.
2323
| --output | output file (If no output is specified then it prints to stdout |
2424
| --type | Type of variable (default: char) |
2525
| --binary | If the file contents are in binary form |
26+
| --nullterm | Add a null character to the end of the file |
2627
| --namespace | A space seperated list of namespaces |
2728
| --formatted | Tabs for formatting |
2829
| --version | Prints my name |
@@ -49,6 +50,7 @@ namespace blah {
4950

5051
static bool formatted;
5152
static bool binary = false;
53+
static bool nullterm = false;
5254

5355
void add_tabs(const int level ){
5456
if(formatted) {
@@ -67,7 +69,6 @@ parse_options(const vector<string>& args) {
6769
options["--file"] = "";
6870
options["--output"] = "";
6971
options["--namespace"] = "";
70-
options["--eof"] = "0";
7172

7273
//Parse Arguments
7374
string curr_opt;
@@ -79,6 +80,9 @@ parse_options(const vector<string>& args) {
7980
else if(arg == "--binary") {
8081
binary = true;
8182
}
83+
else if(arg == "--nullterm") {
84+
nullterm = true;
85+
}
8286
else if(arg == "--formatted") {
8387
formatted = true;
8488
}
@@ -167,7 +171,7 @@ int main(int argc, const char * const * const argv)
167171
}
168172
}
169173

170-
if (options["--eof"].c_str()[0] == '1') {
174+
if (nullterm) {
171175
// Add end of file character
172176
cout << "0x0";
173177
char_cnt++;

src/backend/cuda/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ CL_KERNEL_TO_H(
327327
OUTPUT_DIR ${ptx_headers}
328328
TARGETS ptx_targets
329329
NAMESPACE "cuda"
330-
EOF "1"
330+
NULLTERM TRUE
331331
)
332332

333333
SET(libdevice_bc "")
@@ -363,7 +363,6 @@ IF (${libdevice_bc_len} GREATER 0)
363363
TARGETS libdevice_targets
364364
NAMESPACE "cuda"
365365
BINARY TRUE
366-
EOF "1"
367366
)
368367

369368
MESSAGE(STATUS "LIBDEVICE found.")

src/backend/opencl/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ CL_KERNEL_TO_H(
230230
OUTPUT_DIR ${cl_kernel_headers}
231231
TARGETS cl_kernel_targets
232232
NAMESPACE "opencl"
233-
EOF "0"
234233
)
235234

236235
# OS Definitions

0 commit comments

Comments
 (0)