@@ -26,27 +26,35 @@ struct ur_kernel_handle_t_ {
2626
2727 ~ur_kernel_handle_t_ () {}
2828
29- ur_result_t initWithNative () {
29+ static ur_result_t makeWithNative (native_type NativeKernel,
30+ ur_program_handle_t Program,
31+ ur_context_handle_t Context,
32+ ur_kernel_handle_t &Kernel) {
33+ auto URKernel =
34+ std::make_unique<ur_kernel_handle_t_>(NativeKernel, Program, Context);
3035 if (!Program) {
3136 cl_program CLProgram;
32- CL_RETURN_ON_FAILURE (clGetKernelInfo (
33- Kernel, CL_KERNEL_PROGRAM, sizeof (CLProgram), &CLProgram, nullptr ));
37+ CL_RETURN_ON_FAILURE (clGetKernelInfo (NativeKernel, CL_KERNEL_PROGRAM,
38+ sizeof (CLProgram), &CLProgram,
39+ nullptr ));
3440 ur_native_handle_t NativeProgram =
3541 reinterpret_cast <ur_native_handle_t >(CLProgram);
3642 UR_RETURN_ON_FAILURE (urProgramCreateWithNativeHandle (
37- NativeProgram, nullptr , nullptr , &Program));
43+ NativeProgram, nullptr , nullptr , &(URKernel-> Program ) ));
3844 }
3945 cl_context CLContext;
40- CL_RETURN_ON_FAILURE (clGetKernelInfo (
41- Kernel, CL_KERNEL_CONTEXT, sizeof (CLContext), &CLContext, nullptr ));
46+ CL_RETURN_ON_FAILURE (clGetKernelInfo (NativeKernel, CL_KERNEL_CONTEXT,
47+ sizeof (CLContext), &CLContext,
48+ nullptr ));
4249 if (!Context) {
4350 ur_native_handle_t NativeContext =
4451 reinterpret_cast <ur_native_handle_t >(CLContext);
4552 UR_RETURN_ON_FAILURE (urContextCreateWithNativeHandle (
46- NativeContext, 0 , nullptr , nullptr , &Context));
53+ NativeContext, 0 , nullptr , nullptr , &(URKernel-> Context ) ));
4754 } else if (Context->get () != CLContext) {
4855 return UR_RESULT_ERROR_INVALID_CONTEXT;
4956 }
57+ Kernel = URKernel.release ();
5058 return UR_RESULT_SUCCESS;
5159 }
5260
0 commit comments