@@ -216,8 +216,8 @@ bool CLRuntime::CheckFromPrecompiledBinary(const std::string& program_key,
216
216
" from source." ;
217
217
} else {
218
218
LOG (INFO) << " Load opencl kernel bin file: " << bin_file;
219
- ret = Deserialize (bin_file, &programs_precompiled_binary_);
220
- CHECK (ret ) << " Deserialize failed. " ;
219
+ bool success = Deserialize (bin_file, &programs_precompiled_binary_);
220
+ CHECK (success ) << " Deserialize failed! " ;
221
221
222
222
VLOG (3 ) << " sn_key: " << sn_key_;
223
223
VLOG (3 ) << " map size: " << programs_precompiled_binary_.size ();
@@ -237,9 +237,12 @@ bool CLRuntime::CheckFromPrecompiledBinary(const std::string& program_key,
237
237
} else if (host::memcmp (((sn_iter->second )[0 ]).data (),
238
238
GetSN (build_option).data (),
239
239
GetSN (build_option).length ())) {
240
- LOG (INFO) << " size of sn_info: " << ((sn_iter->second )[0 ]).size ()
241
- << " \n size of GetSN: " << GetSN (build_option).length ()
242
- << " \n GetSN: " << GetSN (build_option);
240
+ std::string sn_str (reinterpret_cast <char *>((sn_iter->second )[0 ].data ()),
241
+ (sn_iter->second )[0 ].size ());
242
+ LOG (INFO) << " \n SN required: " << GetSN (build_option)
243
+ << " \t size: " << GetSN (build_option).length ()
244
+ << " \n SN in bin file: " << sn_str
245
+ << " \t size: " << ((sn_iter->second )[0 ]).size ();
243
246
LOG (WARNING) << " The precompiled OpenCL binary[" << bin_file
244
247
<< " ] is invalid!" ;
245
248
delete_bin_flag = true ;
@@ -250,13 +253,12 @@ bool CLRuntime::CheckFromPrecompiledBinary(const std::string& program_key,
250
253
#endif
251
254
// loop all programs of the binary file
252
255
cl_int status{CL_SUCCESS};
253
- const std::vector<cl::Device> device{*device_};
254
256
for (auto & ins : programs_precompiled_binary_) {
255
257
std::string prog_key = ins.first ;
256
258
if (prog_key == sn_key_) continue ; // skip sn_key
257
259
258
260
cl::Program program (
259
- *context_ , {*device_ }, ins.second , nullptr , &status);
261
+ context () , {device () }, ins.second , nullptr , &status);
260
262
CL_CHECK_FATAL_SOLID (status);
261
263
auto pos_start = prog_key.find_first_of (" -D" );
262
264
std::string options = prog_key.substr (pos_start);
@@ -281,6 +283,8 @@ bool CLRuntime::CheckFromPrecompiledBinary(const std::string& program_key,
281
283
282
284
if (delete_bin_flag) {
283
285
remove_file (bin_file);
286
+ programs_precompiled_binary_.clear ();
287
+ programs_.clear ();
284
288
}
285
289
} else if (gotten_bin_flag_) {
286
290
// This case happened when model has updated. Bin file should be updated
@@ -296,7 +300,7 @@ bool CLRuntime::CheckFromPrecompiledBinary(const std::string& program_key,
296
300
bool CLRuntime::CheckFromSource (const std::string& file_name,
297
301
const std::string& program_key,
298
302
const std::string& build_option) {
299
- auto ptr = CreateProgramFromSource (*context_ , file_name);
303
+ auto ptr = CreateProgramFromSource (context () , file_name);
300
304
auto program = ptr.get ();
301
305
#ifdef LITE_WITH_LOG
302
306
VLOG (3 ) << " --- begin build program from source -> " << program_key
@@ -351,7 +355,7 @@ std::unique_ptr<cl::Program> CLRuntime::CreateProgramFromSource(
351
355
}
352
356
353
357
bool CLRuntime::BuildProgram (cl::Program* program, const std::string& options) {
354
- status_ = program->build ({*device_ }, options.c_str ());
358
+ status_ = program->build ({device () }, options.c_str ());
355
359
CL_CHECK_ERROR (status_);
356
360
357
361
if (status_ != CL_SUCCESS) {
@@ -376,6 +380,13 @@ void CLRuntime::SaveProgram() {
376
380
bool ret = Serialize (binary_file, programs_precompiled_binary_);
377
381
CHECK (ret) << " Serialize failed for opencl binary_file:" << binary_file;
378
382
#ifdef LITE_WITH_LOG
383
+ if (programs_precompiled_binary_.find (sn_key_) !=
384
+ programs_precompiled_binary_.end ()) {
385
+ std::string sn_str (reinterpret_cast <char *>(
386
+ programs_precompiled_binary_[sn_key_][0 ].data ()),
387
+ programs_precompiled_binary_[sn_key_][0 ].size ());
388
+ LOG (INFO) << " SN stored: " << sn_str;
389
+ }
379
390
LOG (INFO) << " Programs have been serialized to disk successfully. File: "
380
391
<< binary_file;
381
392
#endif
@@ -471,14 +482,31 @@ std::string CLRuntime::GetSN(const std::string options) {
471
482
// Identifier info(Serial Number) for each binary file: lite version,
472
483
// build options, platform info, device version, driver version
473
484
STL::stringstream sn_ss;
474
- std::string lite_version = lite::version () + " ; " ;
475
- std::string platform_info = platform_->getInfo <CL_PLATFORM_NAME>() + " , " +
476
- platform_->getInfo <CL_PLATFORM_PROFILE>() + " ; " ;
477
- std::string device_version = device_->getInfo <CL_DEVICE_VERSION>() + " ; " ;
478
- std::string driver_version = device_->getInfo <CL_DRIVER_VERSION>() + " ; " ;
479
- std::string place_holder{" place_holder" };
480
- sn_ss << lite_version << options << platform_info << device_version
481
- << driver_version << place_holder;
485
+
486
+ const std::string aarch =
487
+ #if defined(__aarch64__)
488
+ " android_armv8" ;
489
+ #else
490
+ " android_armv7" ;
491
+ #endif
492
+ #if defined(_WIN64)
493
+ " win64" ;
494
+ #elif defined(_WIN32)
495
+ " win32" ;
496
+ #endif
497
+
498
+ const std::string aarch_info = aarch + " ; " ;
499
+ const std::string lite_version = lite::version () + " ; " ;
500
+ const std::string platform_info =
501
+ platform_->getInfo <CL_PLATFORM_NAME>() + " , " +
502
+ platform_->getInfo <CL_PLATFORM_PROFILE>() + " ; " ;
503
+ const std::string device_version =
504
+ device_->getInfo <CL_DEVICE_VERSION>() + " ; " ;
505
+ const std::string driver_version =
506
+ device_->getInfo <CL_DRIVER_VERSION>() + " ; " ;
507
+ const std::string place_holder{" place_holder" };
508
+ sn_ss << aarch_info << lite_version << options << platform_info
509
+ << device_version << driver_version << place_holder;
482
510
return sn_ss.str ();
483
511
}
484
512
0 commit comments