| 22 | typedef bool (*RegisterDevicePluginEngineFn)(CustomEngineParams* engine_params); |
| 23 | |
| 24 | void LoadCustomLib(const std::string& dso_lib_path, void* dso_handle) { |
| 25 | CustomRuntimeParams runtime_params; |
| 26 | std::memset(&runtime_params, 0, sizeof(CustomRuntimeParams)); |
| 27 | runtime_params.size = sizeof(CustomRuntimeParams); |
| 28 | auto device_interface = std::make_unique<C_DeviceInterface>(); |
| 29 | runtime_params.interface = device_interface.get(); |
| 30 | std::memset(runtime_params.interface, 0, sizeof(C_DeviceInterface)); |
| 31 | runtime_params.interface->size = sizeof(C_DeviceInterface); |
| 32 | |
| 33 | RegisterDevicePluginFn init_plugin_fn = |
| 34 | reinterpret_cast<RegisterDevicePluginFn>(dlsym(dso_handle, "InitPlugin")); |
| 35 | |
| 36 | if (init_plugin_fn == nullptr) { |
| 37 | LOG(WARNING) << "Skipped lib [" << dso_lib_path << "]: fail to find " |
| 38 | << "InitPlugin symbol in this lib."; |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | init_plugin_fn(&runtime_params); |
| 43 | if (runtime_params.device_type == nullptr) { |
| 44 | LOG(WARNING) << "Skipped lib [" << dso_lib_path |
| 45 | << "]: InitPlugin failed, please check the version " |
| 46 | "compatibility between PaddlePaddle and Custom Runtime."; |
| 47 | return; |
| 48 | } |
| 49 | phi::LoadCustomRuntimeLib( |
| 50 | runtime_params, std::move(device_interface), dso_lib_path, dso_handle); |
| 51 | LOG(INFO) << "Succeed in loading custom runtime in lib: " << dso_lib_path; |
| 52 | |
| 53 | RegisterDevicePluginEngineFn init_plugin_engine_fn = |
| 54 | reinterpret_cast<RegisterDevicePluginEngineFn>( |
| 55 | dlsym(dso_handle, "InitPluginCustomEngine")); |
| 56 | |
| 57 | if (init_plugin_engine_fn == nullptr) { |
| 58 | LOG(INFO) << "Skipped lib [" << dso_lib_path << "]: no custom engine " |
| 59 | << "Plugin symbol in this lib."; |
| 60 | } else { |
| 61 | CustomEngineParams engine_params; |
| 62 | std::memset(&engine_params, 0, sizeof(CustomEngineParams)); |
| 63 | engine_params.size = sizeof(CustomEngineParams); |
| 64 | |
| 65 | auto engine_interface = new (C_CustomEngineInterface); |
| 66 | engine_params.interface = engine_interface; |
| 67 | |
| 68 | std::memset(engine_params.interface, 0, sizeof(C_CustomEngineInterface)); |
| 69 | engine_params.interface->size = sizeof(C_CustomEngineInterface); |
| 70 | |
| 71 | init_plugin_engine_fn(&engine_params); |
| 72 | if (engine_params.interface == nullptr) { |
| 73 | LOG(WARNING) << "Skipped lib [" << dso_lib_path |
| 74 | << "]: InitPluginEngine failed, please check the version " |
| 75 | "compatibility between PaddlePaddle and Custom Runtime."; |
| 76 | } else { |
| 77 | paddle::custom_engine::LoadCustomEngineLib(dso_lib_path, &engine_params); |
| 78 | LOG(INFO) << "Succeed in loading custom engine in lib: " << dso_lib_path; |
| 79 | } |
| 80 | } |
| 81 | } |
no test coverage detected