| 122 | } |
| 123 | |
| 124 | void COprLibOption::load_lib() { |
| 125 | auto handle = dlopen(lib_path.c_str(), RTLD_LAZY); |
| 126 | mgb_assert( |
| 127 | handle, "failed to open c opr lib %s:\n errmsg: %s", lib_path.c_str(), |
| 128 | dlerror()); |
| 129 | |
| 130 | const char* entry = m_c_opr_init_func.c_str(); |
| 131 | auto func = dlsym(handle, entry); |
| 132 | mgb_assert( |
| 133 | func, |
| 134 | "can not resolve %s: %s, please use '--c-opr-init-interface' to set the " |
| 135 | "init API of your loader", |
| 136 | entry, dlerror()); |
| 137 | typedef void (*entry_f_t)(void*); |
| 138 | reinterpret_cast<entry_f_t>(func)( |
| 139 | reinterpret_cast<void*>(&mgb_get_extern_c_opr_api_versioned)); |
| 140 | printf("loaded C opr library: %s\n", lib_path.c_str()); |
| 141 | entry = "copr_param_device_ptr_malloc"; |
| 142 | func = dlsym(handle, entry); |
| 143 | if (func) { |
| 144 | printf("get %s from: %s\n", entry, lib_path.c_str()); |
| 145 | c_opr_args.copr_param_device_ptr_malloc = |
| 146 | reinterpret_cast<COprArgs::COPR_PARAM_DEVICE_PTR_MEM_T>(func); |
| 147 | } |
| 148 | |
| 149 | entry = "copr_param_device_ptr_free"; |
| 150 | func = dlsym(handle, entry); |
| 151 | if (func) { |
| 152 | printf("get %s from: %s\n", entry, lib_path.c_str()); |
| 153 | c_opr_args.copr_param_device_ptr_free = |
| 154 | reinterpret_cast<COprArgs::COPR_PARAM_DEVICE_PTR_MEM_T>(func); |
| 155 | } |
| 156 | |
| 157 | entry = "copr_param_device_ptr_h2d"; |
| 158 | func = dlsym(handle, entry); |
| 159 | if (func) { |
| 160 | printf("get %s from: %s\n", entry, lib_path.c_str()); |
| 161 | c_opr_args.copr_param_device_ptr_h2d = |
| 162 | reinterpret_cast<COprArgs::COPR_PARAM_DEVICE_PTR_H2D_T>(func); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | void COprLibOption::set_Copr_IO(std::shared_ptr<ModelBase> model_ptr) { |
| 167 | auto model = std::static_pointer_cast<ModelMdl>(model_ptr); |