@@ -104,7 +104,7 @@ bool OpenCLContext::Init(uint32_t platform_id, uint32_t device_id)
104
104
return true ;
105
105
}
106
106
107
- bool OpenCLContext::Compile (const char * binary_name, const std::initializer_list<std::string>& source_files, const std::initializer_list<std::string>& kernel_names, const std::string& options, CachingParameters caching)
107
+ bool OpenCLContext::Compile (const char * binary_name, const std::initializer_list<std::string>& source_files, const std::initializer_list<std::string>& kernel_names, const std::string& options, CachingParameters caching, uint32_t force_elf_binary_flags )
108
108
{
109
109
std::vector<std::string> source;
110
110
source.reserve (source_files.size ());
@@ -138,7 +138,11 @@ bool OpenCLContext::Compile(const char* binary_name, const std::initializer_list
138
138
buf.insert (buf.begin (), std::istreambuf_iterator<char >(f), std::istreambuf_iterator<char >());
139
139
140
140
const size_t data_length = buf.size ();
141
+ if (force_elf_binary_flags)
142
+ *(uint32_t *)(buf.data () + 0x30 ) = force_elf_binary_flags;
143
+
141
144
const unsigned char * binary_data = reinterpret_cast <const unsigned char *>(buf.data ());
145
+
142
146
program = clCreateProgramWithBinary (context, 1 , &device, &data_length, &binary_data, nullptr , &err);
143
147
CL_CHECK_RESULT (clCreateProgramWithBinary);
144
148
@@ -187,15 +191,17 @@ bool OpenCLContext::Compile(const char* binary_name, const std::initializer_list
187
191
}
188
192
std::cout << " done" << std::endl;
189
193
190
- if (!created_with_binary)
191
- {
192
- size_t bin_size;
193
- CL_CHECKED_CALL (clGetProgramInfo, program, CL_PROGRAM_BINARY_SIZES, sizeof (bin_size), &bin_size, nullptr );
194
+ size_t bin_size;
195
+ CL_CHECKED_CALL (clGetProgramInfo, program, CL_PROGRAM_BINARY_SIZES, sizeof (bin_size), &bin_size, nullptr );
194
196
195
- std::vector<char > binary_data (bin_size);
196
- char * tmp[1 ] = { binary_data.data () };
197
- CL_CHECKED_CALL (clGetProgramInfo, program, CL_PROGRAM_BINARIES, sizeof (tmp), tmp, NULL );
197
+ std::vector<char > binary_data (bin_size);
198
+ char * tmp[1 ] = { binary_data.data () };
199
+ CL_CHECKED_CALL (clGetProgramInfo, program, CL_PROGRAM_BINARIES, sizeof (tmp), tmp, NULL );
198
200
201
+ elf_binary_flags = (bin_size >= 0x34 ) ? *(uint32_t *)(binary_data.data () + 0x30 ) : 0 ;
202
+
203
+ if (!created_with_binary)
204
+ {
199
205
std::ofstream f (binary_name, std::ios::binary);
200
206
f.write (tmp[0 ], bin_size);
201
207
f.close ();
0 commit comments