This routine will query the OpenCL context for it's devices and their hardware limitations, which we synthesize into a hardware "envelope". We only query the devices the first time we're called after the object's context is set. On 2nd and subsequent calls, we just return the pointer.
| 4649 | // we just return the pointer. |
| 4650 | // |
| 4651 | clfftStatus FFTPlan::SetEnvelope () |
| 4652 | { |
| 4653 | |
| 4654 | // TODO The caller has already acquired the lock on *this |
| 4655 | // However, we shouldn't depend on it. |
| 4656 | |
| 4657 | if (0 == envelope.limit_LocalMemSize) do { |
| 4658 | // First time, query OpenCL for the device info |
| 4659 | // |
| 4660 | memset (&envelope, 0, sizeof(envelope)); |
| 4661 | |
| 4662 | // Get the size needed for the device list |
| 4663 | // |
| 4664 | size_t deviceListSize = 0; |
| 4665 | OPENCL_V( ::clGetContextInfo( context, CL_CONTEXT_DEVICES, 0, NULL, &deviceListSize ), |
| 4666 | _T("Getting device array size ( ::clGetContextInfo() )" )); |
| 4667 | cl_uint n = cl_uint (deviceListSize / sizeof(cl_device_id)); |
| 4668 | if (n == 0) break; |
| 4669 | |
| 4670 | std::vector< cl_device_id > devices( n+1 ); |
| 4671 | // Get the device list |
| 4672 | // |
| 4673 | OPENCL_V( ::clGetContextInfo( context, CL_CONTEXT_DEVICES, deviceListSize, &devices[ 0 ], NULL ), |
| 4674 | _T("Getting device array ( ::clGetContextInfo() )") ); |
| 4675 | |
| 4676 | // Get the # of devices |
| 4677 | // |
| 4678 | cl_uint cContextDevices = 0; |
| 4679 | |
| 4680 | size_t deviceVersionSize = 0; |
| 4681 | OPENCL_V( ::clGetDeviceInfo( devices[0], CL_DEVICE_VERSION, 0, NULL, &deviceVersionSize ), |
| 4682 | _T("Getting CL_DEVICE_VERSION Info string size ( ::clGetDeviceInfo() )" )); |
| 4683 | |
| 4684 | std::vector< char > szDeviceVersion( deviceVersionSize ); |
| 4685 | OPENCL_V( ::clGetDeviceInfo( devices[0], CL_DEVICE_VERSION, deviceVersionSize, &szDeviceVersion[ 0 ], NULL ), |
| 4686 | _T("Getting CL_DEVICE_VERSION Platform Info string ( ::clGetDeviceInfo() )" )); |
| 4687 | |
| 4688 | char openclstr[11]="OpenCL 1.0"; |
| 4689 | |
| 4690 | if (!strncmp((const char*)&szDeviceVersion[ 0 ], openclstr, 10)) |
| 4691 | { |
| 4692 | cContextDevices = 1; |
| 4693 | } |
| 4694 | else |
| 4695 | { |
| 4696 | OPENCL_V( ::clGetContextInfo( context, CL_CONTEXT_NUM_DEVICES, sizeof( cContextDevices ), &cContextDevices, NULL ), |
| 4697 | _T("Getting number of context devices ( ::clGetContextInfo() )" )); |
| 4698 | } |
| 4699 | |
| 4700 | cContextDevices = std::min<cl_uint> (cContextDevices, n); |
| 4701 | if (0 == cContextDevices) |
| 4702 | break; |
| 4703 | |
| 4704 | envelope.limit_LocalMemSize = 32768; |
| 4705 | envelope.limit_WorkGroupSize = 256; |
| 4706 | envelope.limit_Dimensions = countOf (envelope.limit_Size); |
| 4707 | for (size_t u = 0; u < countOf (envelope.limit_Size); ++u) { |
| 4708 | envelope.limit_Size[u] = 256; |
no outgoing calls
no test coverage detected