예제 #1
0
파일: context.hpp 프로젝트: DingKe/vexcl
std::pair<std::vector<cl::Context>, std::vector<command_queue>>
queue_list(DevFilter &&filter, cl_command_queue_properties properties = 0) {
    std::vector<cl::Context>      context;
    std::vector<command_queue> queue;

    std::vector<cl::Platform> platforms;
    cl::Platform::get(&platforms);

    for(auto p = platforms.begin(); p != platforms.end(); p++) {
        std::vector<cl::Device> device;
        std::vector<cl::Device> dev_list;

        p->getDevices(CL_DEVICE_TYPE_ALL, &dev_list);

        for(auto d = dev_list.begin(); d != dev_list.end(); d++) {
            if (!d->getInfo<CL_DEVICE_AVAILABLE>()) continue;
            if (!filter(*d)) continue;

            device.push_back(*d);
        }

        if (device.empty()) continue;

        for(auto d = device.begin(); d != device.end(); d++)
            try {
                context.push_back(cl::Context(std::vector<cl::Device>(1, *d)));
                queue.push_back(command_queue(context.back(), *d, properties));
            } catch(const cl::Error&) {
                // Something bad happened. Better skip this device.
            }
    }

    return std::make_pair(context, queue);
}
예제 #2
0
void OpenCLInterface::printOCLDeviceInfo(const cl::Device &device) const {
	std::string device_name;
	std::string device_vendor;
	cl_int error;
	error = device.getInfo(CL_DEVICE_NAME, &device_name);
	if (error != CL_SUCCESS) {
		Logger::writeLine("OpenCLInterface::printOCLDeviceInfo(): Error during query for CL_DEVICE_NAME: " + std::to_string(error));
	}
	error = device.getInfo(CL_DEVICE_VENDOR, &device_vendor);
	if (error != CL_SUCCESS) {
		Logger::writeLine("OpenCLInterface::printOCLDeviceInfo(): Error during query for CL_DEVICE_VENDOR: " + std::to_string(error));
	}
	Logger::writeLine("OpenCLInterface::printOCLDeviceInfo(): OpenCL device info: " + device_name + ", vendor " + device_vendor + ".");
}
예제 #3
0
std::string Convolution3DCLBuffer::getDeviceInfo(cl::Device device, cl_device_info info)
{
	std::string result;
	status = device.getInfo(info,&result);
	CHECK_ERROR(status, "cl::Device::getInfo");
	return result;
}
예제 #4
0
std::string Convolution3DCLBuffer::getDeviceName(cl::Device device)
{
	std::string result;
	cl_int status = device.getInfo(CL_DEVICE_NAME,&result);
	CHECK_ERROR(status, "cl::Device::getInfo");
	return result;
}
예제 #5
0
파일: CLGL.cpp 프로젝트: tlgimenes/clgl
/*
 * Get the info from device dev
 */
void CLGL::CLGLGetDevicesInfo(cl::Device dev, cl_device_info name, std::string * info)
{
  try{
    dev.getInfo(name, info);
  }
  catch(cl::Error error){
    std::cout << error.what() << " " << CLGLError::errToStr(error.err()) << std::endl;
  }
  
  return;
}
예제 #6
0
 OGLSharedFramebuffer::OGLSharedFramebuffer(CL::Device& device,
                                            const ivec2& size, int tile_size) :
     Framebuffer(device, size, tile_size),
     _tex_buffer(_act_size.x * _act_size.y * sizeof(vec4), GL_RGBA32F),
     _shared(device.share_gl()),
     _local(0)
 {
     if (_shared) {
         _cl_buffer = new CL::Buffer(device, _tex_buffer.get_buffer());
     } else {
         _cl_buffer = new CL::Buffer(device, _tex_buffer.get_size(), CL_MEM_READ_WRITE);
         _local = malloc(_tex_buffer.get_size());
     }
 }
예제 #7
0
파일: context.hpp 프로젝트: DingKe/vexcl
std::vector<cl::Device> device_list(DevFilter&& filter) {
    std::vector<cl::Device> device;

    std::vector<cl::Platform> platforms;
    cl::Platform::get(&platforms);

    for(auto p = platforms.begin(); p != platforms.end(); p++) {
        std::vector<cl::Device> dev_list;

        p->getDevices(CL_DEVICE_TYPE_ALL, &dev_list);

        for(auto d = dev_list.begin(); d != dev_list.end(); d++) {
            if (!d->getInfo<CL_DEVICE_AVAILABLE>()) continue;
            if (!filter(*d)) continue;

            device.push_back(*d);
        }
    }

    return device;
}
예제 #8
0
파일: Global.cpp 프로젝트: Magnum69/TBT
	cl_ulong getLocalMemSize(const cl::Device &device)
	{
		cl_ulong localMemSize;
		device.getInfo(CL_DEVICE_LOCAL_MEM_SIZE, &localMemSize);
		return localMemSize;
	}
예제 #9
0
파일: Global.cpp 프로젝트: Magnum69/TBT
	size_t getMaxWorkGroupSize(const cl::Device &device)
	{
		size_t maxWorkGroupSize;
		device.getInfo(CL_DEVICE_MAX_WORK_GROUP_SIZE, &maxWorkGroupSize);
		return maxWorkGroupSize;
	}
예제 #10
0
파일: Global.cpp 프로젝트: Magnum69/TBT
	cl_uint getMaxComputeUnits(const cl::Device &device)
	{
		cl_uint nComputeUnits;
		device.getInfo(CL_DEVICE_MAX_COMPUTE_UNITS, &nComputeUnits);
		return nComputeUnits;
	}
예제 #11
0
파일: Global.cpp 프로젝트: Magnum69/TBT
	cl_device_type getType(const cl::Device &device)
	{
		cl_device_type deviceType;
		device.getInfo(CL_DEVICE_TYPE, &deviceType);
		return deviceType;
	}
예제 #12
0
파일: context.hpp 프로젝트: DingKe/vexcl
namespace opencl {

typedef cl::Context                 context;
typedef cl::Device                  device;
typedef cl::CommandQueue            command_queue;
typedef cl_command_queue_properties command_queue_properties;
typedef cl_device_id                device_id;
typedef cl::NDRange                 ndrange;

/// Binds the specified context to the calling CPU thread.
/**
 * With the OpenCL backend this is an empty stub provided for compatibility
 * with the CUDA backend.
 */
inline void select_context(const command_queue&) {
}

/// Returns id of the device associated with the given queue.
inline device_id get_device_id(const command_queue &q) {
    return q.getInfo<CL_QUEUE_DEVICE>()();
}

/// \cond INTERNAL
typedef cl_context       context_id;
/// Returns raw context id for the given queue.
inline context_id get_context_id(const command_queue &q) {
    return q.getInfo<CL_QUEUE_CONTEXT>()();
}

/// Returns context for the given queue.
inline context get_context(const command_queue &q) {
    return q.getInfo<CL_QUEUE_CONTEXT>();
}

/// Compares contexts by raw ids.
struct compare_contexts {
    bool operator()(const context &a, const context &b) const {
        return a() < b();
    }
};

/// Compares queues by raw ids.
struct compare_queues {
    bool operator()(const command_queue &a, const command_queue &b) const {
        return a() < b();
    }
};
/// \endcond

/// Create command queue on the same context and device as the given one.
inline command_queue duplicate_queue(const command_queue &q) {
    return command_queue(
            q.getInfo<CL_QUEUE_CONTEXT>(), q.getInfo<CL_QUEUE_DEVICE>());
}

/// Checks if the compute device is CPU.
inline bool is_cpu(const command_queue &q) {
    cl::Device d = q.getInfo<CL_QUEUE_DEVICE>();
#ifdef _MSC_VER
#  pragma warning(push)
#  pragma warning(disable: 4800)
#endif
    return d.getInfo<CL_DEVICE_TYPE>() & CL_DEVICE_TYPE_CPU;
#ifdef _MSC_VER
#  pragma warning(pop)
#endif
}

/// Select devices by given criteria.
/**
 * \param filter  Device filter functor. Functors may be combined with logical
 *                operators.
 * \returns list of devices satisfying the provided filter.
 *
 * This example selects any GPU which supports double precision arithmetic:
 \code
 auto devices = device_list(
          Filter::Type(CL_DEVICE_TYPE_GPU) && Filter::DoublePrecision
          );
 \endcode
 */
template<class DevFilter>
std::vector<cl::Device> device_list(DevFilter&& filter) {
    std::vector<cl::Device> device;

    std::vector<cl::Platform> platforms;
    cl::Platform::get(&platforms);

    for(auto p = platforms.begin(); p != platforms.end(); p++) {
        std::vector<cl::Device> dev_list;

        p->getDevices(CL_DEVICE_TYPE_ALL, &dev_list);

        for(auto d = dev_list.begin(); d != dev_list.end(); d++) {
            if (!d->getInfo<CL_DEVICE_AVAILABLE>()) continue;
            if (!filter(*d)) continue;

            device.push_back(*d);
        }
    }

    return device;
}

/// Create command queues on devices by given criteria.
/**
 * \param filter  Device filter functor. Functors may be combined with logical
 *                operators.
 * \param properties Command queue properties.
 *
 * \returns list of queues accociated with selected devices.
 * \see device_list
 */
template<class DevFilter>
std::pair<std::vector<cl::Context>, std::vector<command_queue>>
queue_list(DevFilter &&filter, cl_command_queue_properties properties = 0) {
    std::vector<cl::Context>      context;
    std::vector<command_queue> queue;

    std::vector<cl::Platform> platforms;
    cl::Platform::get(&platforms);

    for(auto p = platforms.begin(); p != platforms.end(); p++) {
        std::vector<cl::Device> device;
        std::vector<cl::Device> dev_list;

        p->getDevices(CL_DEVICE_TYPE_ALL, &dev_list);

        for(auto d = dev_list.begin(); d != dev_list.end(); d++) {
            if (!d->getInfo<CL_DEVICE_AVAILABLE>()) continue;
            if (!filter(*d)) continue;

            device.push_back(*d);
        }

        if (device.empty()) continue;

        for(auto d = device.begin(); d != device.end(); d++)
            try {
                context.push_back(cl::Context(std::vector<cl::Device>(1, *d)));
                queue.push_back(command_queue(context.back(), *d, properties));
            } catch(const cl::Error&) {
                // Something bad happened. Better skip this device.
            }
    }

    return std::make_pair(context, queue);
}

} // namespace opencl
예제 #13
0
 void printDeviceInfo(const cl::Device &device, cl_device_info info) {
     if (!initialized) {
         printf("not initialized. call initCLUtility().");
     }
     
     printf("%s: ", clDeviceInfoMetaInfos[info].name);
     
     switch (clDeviceInfoMetaInfos[info].infoType) {
         case CLDeviceInfoType_bool: {
             cl_bool val;
             device.getInfo(info, &val);
             printf(val != 0 ? "YES" : "NO");
             break;
         }
         case CLDeviceInfoType_uint: {
             cl_uint val;
             device.getInfo(info, &val);
             printf("%u", val);
             break;
         }
         case CLDeviceInfoType_ulong: {
             cl_ulong val;
             device.getInfo(info, &val);
             printf("%llu", val);
             break;
         }
         case CLDeviceInfoType_size_t: {
             size_t val;
             device.getInfo(info, &val);
             printf("%lu", val);
             break;
         }
         case CLDeviceInfoType_string: {
             std::string val;
             device.getInfo(info, &val);
             printf("%s", val.c_str());
             break;
         }
         case CLDeviceInfoType_size_t_vec: {
             VECTOR_CLASS<size_t> val;
             device.getInfo(info, &val);
             for (uint32_t i = 0; i < val.size() - 1; ++i) {
                 printf("%lu, ", val[i]);
             }
             printf("%lu", val.back());
             break;
         }
         case CLDeviceInfoType_device_id: {
             cl_device_id val;
             device.getInfo(info, &val);
             printf("%#018llx", (uint64_t)val);
             break;
         }
         case CLDeviceInfoType_platform_id: {
             cl_platform_id val;
             device.getInfo(info, &val);
             printf("%#018llx", (uint64_t)val);
             break;
         }
         case CLDeviceInfoType_device_type: {
             cl_device_type val;
             device.getInfo(info, &val);
             switch (val) {
                 case CL_DEVICE_TYPE_CPU:
                     printf("CPU");
                     break;
                 case CL_DEVICE_TYPE_GPU:
                     printf("GPU");
                     break;
                 case CL_DEVICE_TYPE_ACCELERATOR:
                     printf("Accelerator");
                     break;
                 case CL_DEVICE_TYPE_CUSTOM:
                     printf("Custom");
                     break;
                 default:
                     break;
             }
             break;
         }
         case CLDeviceInfoType_device_fp_config: {
             cl_device_fp_config val;
             device.getInfo(info, &val);
             if ((val & CL_FP_DENORM) != 0)
                 printf("CL_FP_DENORM ");
             if ((val & CL_FP_INF_NAN) != 0)
                 printf("CL_FP_INF_NAN ");
             if ((val & CL_FP_ROUND_TO_NEAREST) != 0)
                 printf("CL_FP_ROUND_TO_NEAREST ");
             if ((val & CL_FP_ROUND_TO_ZERO) != 0)
                 printf("CL_FP_ROUND_TO_ZERO ");
             if ((val & CL_FP_ROUND_TO_INF) != 0)
                 printf("CL_FP_ROUND_TO_INF ");
             if ((val & CL_FP_FMA) != 0)
                 printf("CL_FP_FMA ");
             if ((val & CL_FP_SOFT_FLOAT) != 0)
                 printf("CL_FP_SOFT_FLOAT ");
             if ((val & CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT) != 0)
                 printf("CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT ");
             break;
         }
         case CLDeviceInfoType_device_local_mem_type: {
             cl_device_local_mem_type val;
             device.getInfo(info, &val);
             switch (val) {
                 case CL_LOCAL:
                     printf("Local");
                     break;
                 case CL_GLOBAL:
                     printf("Global");
                 default:
                     break;
             }
             break;
         }
         case CLDeviceInfoType_device_mem_cache_type: {
             cl_device_mem_cache_type val;
             device.getInfo(info, &val);
             switch (val) {
                 case CL_NONE:
                     printf("None");
                     break;
                 case CL_READ_ONLY_CACHE:
                     printf("Read Only Cache");
                     break;
                 case CL_READ_WRITE_CACHE:
                     printf("Read Write Cache");
                     break;
                 default:
                     break;
             }
             break;
         }
         case CLDeviceInfoType_device_exec_capabilities: {
             cl_device_exec_capabilities val;
             device.getInfo(info, &val);
             if ((val & CL_EXEC_KERNEL) != 0)
                 printf("CL_EXEC_KERNEL ");
             if ((val & CL_EXEC_NATIVE_KERNEL) != 0)
                 printf("CL_EXEC_NATIVE_KERNEL ");
             break;
         }
         case CLDeviceInfoType_command_queue_properties: {
             cl_command_queue_properties val;
             device.getInfo(info, &val);
             if ((val & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) != 0)
                 printf("CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE ");
             if ((val & CL_QUEUE_PROFILING_ENABLE) != 0)
                 printf("CL_QUEUE_PROFILING_ENABLE ");
             break;
         }
         case CLDeviceInfoType_device_affinity_domain: {
             cl_device_affinity_domain val;
             device.getInfo(info, &val);
             if ((val & CL_DEVICE_AFFINITY_DOMAIN_NUMA) != 0)
                 printf("CL_DEVICE_AFFINITY_DOMAIN_NUMA ");
             if ((val & CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE) != 0)
                 printf("CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE ");
             if ((val & CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE) != 0)
                 printf("CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE ");
             if ((val & CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE) != 0)
                 printf("CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE ");
             if ((val & CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE) != 0)
                 printf("CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE ");
             if ((val & CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE) != 0)
                 printf("CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE ");
             break;
         }
         case CLDeviceInfoType_device_partition_property_vec: {
             VECTOR_CLASS<cl_device_partition_property> val;
             device.getInfo(info, &val);
             for (uint32_t i = 0; i < val.size(); ++i) {
                 switch (val[i]) {
                     case CL_DEVICE_PARTITION_EQUALLY:
                         printf("CL_DEVICE_PARTITION_EQUALLY");
                         break;
                     case CL_DEVICE_PARTITION_BY_COUNTS:
                         printf("CL_DEVICE_PARTITION_BY_COUNTS");
                         break;
                     case CL_DEVICE_PARTITION_BY_COUNTS_LIST_END:
                         printf("CL_DEVICE_PARTITION_BY_COUNTS_LIST_END");
                         break;
                     case CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN:
                         printf("CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN");
                         break;
                     default:
                         break;
                 }
                 if (i < val.size() - 1)
                     printf(", ");
             }
             break;
         }
         default:
             break;
     }
     printf("\n");
 }