Ejemplo n.º 1
0
    std::vector<device> init_devices(cl_platform_id platform_id)
    {
            cl_uint n = 0;
            cl_int err = CL_SUCCESS;
            err = ::clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_ALL, 0, NULL, &n);
            OCLM_THROW_IF_EXCEPTION(err, "clGetDeviceIDs");
            std::vector<cl_device_id> device_ids(n);
            err = ::clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_ALL, n, &device_ids[0], NULL);
            OCLM_THROW_IF_EXCEPTION(err, "clGetDeviceIDs");

            std::vector<device> devices(n);
            std::copy(device_ids.begin(), device_ids.end(), devices.begin());

            return devices;
    }
Ejemplo n.º 2
0
    std::vector<device> devices(cl_device_type type = CL_DEVICE_TYPE_ALL) const
    {
        size_t count = device_count(type);

        std::vector<cl_device_id> device_ids(count);
        cl_int ret = clGetDeviceIDs(m_platform,
                                    type,
                                    static_cast<cl_uint>(count),
                                    &device_ids[0],
                                    0);
        if(ret != CL_SUCCESS){
            BOOST_THROW_EXCEPTION(runtime_exception(ret));
        }

        std::vector<device> devices;
        for(cl_uint i = 0; i < count; i++){
            devices.push_back(device(device_ids[i]));
        }

        return devices;
    }
Ejemplo n.º 3
0
util::DynArray<ClState::Device> ClState::queryPlatformDevices(const Platform& p){
	// Querytetään laitteet
	
	util::DynArray<Device> devices;
	
	cl_int err2=0;
	
	cl_uint device_count;
	
	err2 = clGetDeviceIDs(p.id, CL_DEVICE_TYPE_ALL, 0, NULL, &device_count);
	errorCheck("ClState::ClState(): Error on clGetDeviceIDs 1: ", err2);

	std::vector<cl_device_id> device_ids(device_count);

	err2 = clGetDeviceIDs(p.id, CL_DEVICE_TYPE_ALL, device_count, device_ids.data(), NULL);
	errorCheck("CLstate::ClState(): Error on clGetDeviceIDs 2: ", err2);
	
	
	for (uint32 i=0; i<device_count; ++i){
		Device d;
		d.id= device_ids[i];
		d.platform= p;
		
		
		
		size_t ret_size;
		
		cl_bool available;
		
		
		// Onko käytettävissä
		err2= clGetDeviceInfo(d.id, CL_DEVICE_AVAILABLE, sizeof(available), &available, &ret_size);
		errorCheck("ClState::queryPlatformDevices(): Error on clGetDeviceInfo: ", err2);
		
		if (!available) continue;
		
		
		
		// Onko kääntötuki
		err2= clGetDeviceInfo(d.id, CL_DEVICE_COMPILER_AVAILABLE, sizeof(available), &available, &ret_size);
		errorCheck("ClState::queryPlatformDevices(): Error on clGetDeviceInfo: ", err2);
	
		if (!available) continue;
		
		
		// Minkä tyyppinen laite
		
		cl_device_type type[5];
		err2= clGetDeviceInfo(d.id, CL_DEVICE_TYPE, sizeof(type), &type, &ret_size);
		errorCheck("ClState::queryPlatformDevices(): Error on clGetDeviceInfo: ", err2);
		
		d.type= Device::Other;
		d.isDefault= false;
		//print(debug::Ch::OpenCL, debug::Vb::Trivial, "CL_DEVICE_TYPE ret: %i", ret_size);
		for (uint32 j=0; j<ret_size/sizeof(cl_device_type); ++j){
			//print(debug::Ch::OpenCL, debug::Vb::Trivial, "   %i", type[j]);
			switch (type[j]){
				case CL_DEVICE_TYPE_DEFAULT: d.isDefault= true; break;
				case CL_DEVICE_TYPE_CPU: d.type= Device::Cpu; break;
				case CL_DEVICE_TYPE_GPU: d.type= Device::Gpu; break;
				case CL_DEVICE_TYPE_ACCELERATOR: d.type= Device::Accelerator; break;
				
				default: break;
			}

		}
		
		
		// Laitteen nimi
		
		char buf[512];
		
		err2= clGetDeviceInfo(d.id, CL_DEVICE_NAME, sizeof(buf), &buf, &ret_size);
		errorCheck("ClState::queryPlatformDevices(): Error on clGetDeviceInfo: ", err2);
		
		d.name= buf;
		
		
		devices.pushBack(d);
		
	}
	
	return devices;
}