@@ -104,7 +104,7 @@ bool OpenCLContext::Init(uint32_t platform_id, uint32_t device_id)
104104 return true ;
105105}
106106
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 )
108108{
109109 std::vector<std::string> source;
110110 source.reserve (source_files.size ());
@@ -138,7 +138,11 @@ bool OpenCLContext::Compile(const char* binary_name, const std::initializer_list
138138 buf.insert (buf.begin (), std::istreambuf_iterator<char >(f), std::istreambuf_iterator<char >());
139139
140140 const size_t data_length = buf.size ();
141+ if (force_elf_binary_flags)
142+ *(uint32_t *)(buf.data () + 0x30 ) = force_elf_binary_flags;
143+
141144 const unsigned char * binary_data = reinterpret_cast <const unsigned char *>(buf.data ());
145+
142146 program = clCreateProgramWithBinary (context, 1 , &device, &data_length, &binary_data, nullptr , &err);
143147 CL_CHECK_RESULT (clCreateProgramWithBinary);
144148
@@ -187,15 +191,17 @@ bool OpenCLContext::Compile(const char* binary_name, const std::initializer_list
187191 }
188192 std::cout << " done" << std::endl;
189193
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 );
194196
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 );
198200
201+ elf_binary_flags = (bin_size >= 0x34 ) ? *(uint32_t *)(binary_data.data () + 0x30 ) : 0 ;
202+
203+ if (!created_with_binary)
204+ {
199205 std::ofstream f (binary_name, std::ios::binary);
200206 f.write (tmp[0 ], bin_size);
201207 f.close ();
0 commit comments