Skip to content

Commit 1db2c19

Browse files
shehzan10pavanky
authored andcommitted
Fixes to bin2cpp when reading binary files on windows
1 parent 012e483 commit 1db2c19

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

CMakeModules/CLKernelToH.cmake

Lines changed: 7 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;EOF" "SOURCES" ${ARGN})
31+
cmake_parse_arguments(RTCS "" "VARNAME;EXTENSION;OUTPUT_DIR;TARGETS;NAMESPACE;BINARY;EOF" "SOURCES" ${ARGN})
3232

3333
set(_output_files "")
3434
foreach(_input_file ${RTCS_SOURCES})
@@ -38,6 +38,11 @@ function(CL_KERNEL_TO_H)
3838
get_filename_component(_name_we "${_input_file}" NAME_WE)
3939

4040
set(_namespace "${RTCS_NAMESPACE}")
41+
set(_binary "")
42+
if(${RTCS_BINARY})
43+
set(_binary "--binary")
44+
endif(${RTCS_BINARY})
45+
4146
string(REPLACE "." "_" var_name ${var_name})
4247

4348
set(_output_path "${CMAKE_CURRENT_BINARY_DIR}/${RTCS_OUTPUT_DIR}")
@@ -48,7 +53,7 @@ function(CL_KERNEL_TO_H)
4853
DEPENDS ${_input_file} ${BIN2CPP_PROGRAM}
4954
COMMAND ${CMAKE_COMMAND} -E make_directory "${_output_path}"
5055
COMMAND ${CMAKE_COMMAND} -E echo "\\#include \\<${_path}/${_name_we}.hpp\\>" >>"${_output_file}"
51-
COMMAND ${BIN2CPP_PROGRAM} --file ${_name} --namespace ${_namespace} --output ${_output_file} --name ${var_name} --eof ${RTCS_EOF}
56+
COMMAND ${BIN2CPP_PROGRAM} --file ${_name} --namespace ${_namespace} --output ${_output_file} --name ${var_name} ${_binary} --eof ${RTCS_EOF}
5257
WORKING_DIRECTORY "${_path}"
5358
COMMENT "Compiling ${_input_file} to C++ source"
5459
)

CMakeModules/bin2cpp.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ xxd but adds support for namespaces.
2222
| --file | input file |
2323
| --output | output file (If no output is specified then it prints to stdout |
2424
| --type | Type of variable (default: char) |
25+
| --binary | If the file contents are in binary form |
2526
| --namespace | A space seperated list of namespaces |
2627
| --formatted | Tabs for formatting |
2728
| --version | Prints my name |
@@ -47,6 +48,7 @@ namespace blah {
4748
}
4849

4950
static bool formatted;
51+
static bool binary = false;
5052

5153
void add_tabs(const int level ){
5254
if(formatted) {
@@ -74,6 +76,9 @@ parse_options(const vector<string>& args) {
7476
if(arg == "--verbose") {
7577
verbose = true;
7678
}
79+
else if(arg == "--binary") {
80+
binary = true;
81+
}
7782
else if(arg == "--formatted") {
7883
formatted = true;
7984
}
@@ -150,7 +155,7 @@ int main(int argc, const char * const * const argv)
150155
// Always create unsigned char to avoid narrowing
151156
cout << "static const " << "unsigned char" << " " << options["--name"] << "_uchar [] = {\n";
152157

153-
ifstream input(options["--file"]);
158+
ifstream input(options["--file"], (binary ? std::ios::binary : std::ios::in));
154159
size_t char_cnt = 0;
155160
add_tabs(++level);
156161
for(char i; input.get(i);) {

src/backend/cuda/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ IF (${libdevice_bc_len} GREATER 0)
348348
OUTPUT_DIR ${libdevice_headers}
349349
TARGETS libdevice_targets
350350
NAMESPACE "cuda"
351+
BINARY TRUE
351352
EOF "1"
352353
)
353354

0 commit comments

Comments
 (0)