@@ -18,20 +18,16 @@ ur_result_t cl_adapter::getDevicesFromContext(
1818 ur_context_handle_t hContext,
1919 std::unique_ptr<std::vector<cl_device_id>> &DevicesInCtx) {
2020
21- cl_uint DeviceCount;
22- CL_RETURN_ON_FAILURE (clGetContextInfo (cl_adapter::cast<cl_context>(hContext),
23- CL_CONTEXT_NUM_DEVICES, sizeof (cl_uint),
24- &DeviceCount, nullptr ));
21+ cl_uint DeviceCount = hContext->DeviceCount ;
2522
2623 if (DeviceCount < 1 ) {
2724 return UR_RESULT_ERROR_INVALID_CONTEXT;
2825 }
2926
3027 DevicesInCtx = std::make_unique<std::vector<cl_device_id>>(DeviceCount);
31-
32- CL_RETURN_ON_FAILURE (clGetContextInfo (
33- cl_adapter::cast<cl_context>(hContext), CL_CONTEXT_DEVICES,
34- DeviceCount * sizeof (cl_device_id), (*DevicesInCtx).data (), nullptr ));
28+ for (size_t i = 0 ; i < DeviceCount; i++) {
29+ (*DevicesInCtx)[i] = hContext->Devices [i]->get ();
30+ }
3531
3632 return UR_RESULT_SUCCESS;
3733}
@@ -41,11 +37,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextCreate(
4137 const ur_context_properties_t *, ur_context_handle_t *phContext) {
4238
4339 cl_int Ret;
44- *phContext = cl_adapter::cast<ur_context_handle_t >(
45- clCreateContext (nullptr , cl_adapter::cast<cl_uint>(DeviceCount),
46- cl_adapter::cast<const cl_device_id *>(phDevices),
47- nullptr , nullptr , cl_adapter::cast<cl_int *>(&Ret)));
40+ std::vector<cl_device_id> CLDevices (DeviceCount);
41+ for (size_t i = 0 ; i < DeviceCount; i++) {
42+ CLDevices[i] = phDevices[i]->get ();
43+ }
44+
45+ cl_context Ctx = clCreateContext (nullptr , cl_adapter::cast<cl_uint>(DeviceCount),
46+ CLDevices.data (),
47+ nullptr , nullptr , cl_adapter::cast<cl_int *>(&Ret));
4848
49+ *phContext = new ur_context_handle_t_ (Ctx, DeviceCount, phDevices);
4950 return mapCLErrorToUR (Ret);
5051}
5152
@@ -95,7 +96,7 @@ urContextGetInfo(ur_context_handle_t hContext, ur_context_info_t propName,
9596 case UR_CONTEXT_INFO_REFERENCE_COUNT: {
9697 size_t CheckPropSize = 0 ;
9798 auto ClResult =
98- clGetContextInfo (cl_adapter::cast<cl_context>(hContext ), CLPropName,
99+ clGetContextInfo (hContext-> get ( ), CLPropName,
99100 propSize, pPropValue, &CheckPropSize);
100101 if (pPropValue && CheckPropSize != propSize) {
101102 return UR_RESULT_ERROR_INVALID_SIZE;
@@ -114,29 +115,31 @@ urContextGetInfo(ur_context_handle_t hContext, ur_context_info_t propName,
114115UR_APIEXPORT ur_result_t UR_APICALL
115116urContextRelease (ur_context_handle_t hContext) {
116117
117- cl_int Ret = clReleaseContext (cl_adapter::cast<cl_context>(hContext ));
118+ cl_int Ret = clReleaseContext (hContext-> get ( ));
118119 return mapCLErrorToUR (Ret);
119120}
120121
121122UR_APIEXPORT ur_result_t UR_APICALL
122123urContextRetain (ur_context_handle_t hContext) {
123124
124- cl_int Ret = clRetainContext (cl_adapter::cast<cl_context>(hContext ));
125+ cl_int Ret = clRetainContext (hContext-> get ( ));
125126 return mapCLErrorToUR (Ret);
126127}
127128
128129UR_APIEXPORT ur_result_t UR_APICALL urContextGetNativeHandle (
129130 ur_context_handle_t hContext, ur_native_handle_t *phNativeContext) {
130131
131- *phNativeContext = reinterpret_cast <ur_native_handle_t >(hContext);
132+ *phNativeContext = reinterpret_cast <ur_native_handle_t >(hContext-> get () );
132133 return UR_RESULT_SUCCESS;
133134}
134135
135136UR_APIEXPORT ur_result_t UR_APICALL urContextCreateWithNativeHandle (
136- ur_native_handle_t hNativeContext, uint32_t , const ur_device_handle_t *,
137+ ur_native_handle_t hNativeContext, uint32_t numDevices , const ur_device_handle_t *phDevices ,
137138 const ur_context_native_properties_t *, ur_context_handle_t *phContext) {
138139
139- *phContext = reinterpret_cast <ur_context_handle_t >(hNativeContext);
140+ cl_context NativeHandle =
141+ reinterpret_cast <cl_context>(hNativeContext);
142+ *phContext = new ur_context_handle_t_ (NativeHandle, numDevices, phDevices);
140143 return UR_RESULT_SUCCESS;
141144}
142145
@@ -187,7 +190,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextSetExtendedDeleter(
187190 C->execute ();
188191 };
189192 CL_RETURN_ON_FAILURE (clSetContextDestructorCallback (
190- cl_adapter::cast<cl_context>(hContext ), ClCallback, Callback));
193+ hContext-> get ( ), ClCallback, Callback));
191194
192195 return UR_RESULT_SUCCESS;
193196}
0 commit comments