Пример #1
0
void OpenCLInterface::printOCLPlatformInfo(const cl::Platform &platform) const {
	std::string platform_name;
	std::string platform_vendor;
	cl_int error;
	error = platform.getInfo(CL_PLATFORM_NAME, &platform_name);
	if (error != CL_SUCCESS) {
		Logger::writeLine("OpenCLInterface::printOCLPlatformInfo(): Error during query for CL_PLATFORM_NAME: " + std::to_string(error));
	}
	error = platform.getInfo(CL_PLATFORM_VENDOR, &platform_vendor);
	if (error != CL_SUCCESS) {
		Logger::writeLine("OpenCLInterface::printOCLPlatformInfo(): Error during query for CL_PLATFORM_VENDOR: " + std::to_string(error));
	}
	Logger::writeLine("OpenCLInterface::printOCLPlatformInfo(): OpenCL platform info: " + platform_name + ", vendor " + platform_vendor + ".");
}
Пример #2
0
// ****************************************************************************
// Method: OpenCLPlatform::OpenCLPlatform
//
// Purpose:
//   Constructor. Creates a new OpenCL platform representation for the
//   specified patform ID.
//
// Arguments:
//   clPlatform: the platform to be created
//
// Returns:
//
// Note:
//
// Programmer: Gabriel Marin
// Creation: September 22, 2009
//
// Modifications:
//
// ****************************************************************************
OpenCLPlatform::OpenCLPlatform (cl::Platform &clPlatform) :
           Platform<OpenCLDeviceInfo>()
{
    int err;
    platformName = clPlatform.getInfo<CL_PLATFORM_NAME>();
    platformVendor = clPlatform.getInfo<CL_PLATFORM_VENDOR>();
    platformVersion = clPlatform.getInfo<CL_PLATFORM_VERSION>();
    platformExtensions = clPlatform.getInfo<CL_PLATFORM_EXTENSIONS>();

    // query devices
    std::vector<cl::Device> devs;
    err = clPlatform.getDevices( CL_DEVICE_TYPE_ALL, &devs );
    // I should not print an error message here if no devices are present.
    // I will just report that there are zero devices.
//    CL_CHECK_ERROR( err );

    for( vector<cl::Device>::iterator diter = devs.begin();
        diter != devs.end();
        diter++ )
    {
        OpenCLDeviceInfo* openclDevice = new OpenCLDeviceInfo( (*diter)() );
        devices.push_back( openclDevice );
        ++ deviceCount;
    }
}
Пример #3
0
void printAllDevices(cl::Platform platform) {
  // init device
  std::vector<cl::Device> all_devices;
  platform.getDevices(CL_DEVICE_TYPE_ALL, &all_devices);
  std::cout << "Finding devices: " << all_devices.size() << std::endl;

  // walk through devices
  for (auto &device : all_devices) {
    std::cout << "CL_DEVICE_NAME: "
              << device.getInfo<CL_DEVICE_NAME>() << std::endl;
    std::cout << "CL_DEVICE_TYPE: "
              << beautyDevType(device.getInfo<CL_DEVICE_TYPE>()) << std::endl;
    std::cout << "CL_DEVICE_MAX_COMPUTE_UNITS: "
              << device.getInfo<CL_DEVICE_MAX_COMPUTE_UNITS>() << std::endl;
    std::cout << "CL_DEVICE_MAX_WORK_GROUP_SIZE: "
              << device.getInfo<CL_DEVICE_MAX_WORK_GROUP_SIZE>() << std::endl;
    std::cout << "CL_DEVICE_MAX_WORK_ITEM_SIZES[0]: "
              << device.getInfo<CL_DEVICE_MAX_WORK_ITEM_SIZES>()[0] << std::endl;
    std::cout << "CL_DEVICE_GLOBAL_MEM_SIZE: "
              << beautyMem(device.getInfo<CL_DEVICE_GLOBAL_MEM_SIZE>()) << std::endl;
    std::cout << "CL_DEVICE_LOCAL_MEM_SIZE: "
              << beautyMem(device.getInfo<CL_DEVICE_LOCAL_MEM_SIZE>()) << std::endl;
    std::cout << std::endl;
  }
}
Пример #4
0
std::string Convolution3DCLBuffer::getPlatformInfo(cl::Platform platform, cl_platform_info info)
{
	std::string result;
	cl_int status = platform.getInfo(info,&result);
	CHECK_ERROR(status, "cl::Platform::getInfo");
	return result;
}
Пример #5
0
void printDevices( std::vector<cl::Device> devices, cl::Platform platform ){

	// name of the current platform for debugging messages
	std::string platformName;
	platform.getInfo((cl_platform_info)CL_PLATFORM_NAME, &platformName);

	// print informations on devices
	cout << devices.size() << " devices found on " << platformName << ".\n";
	for( auto dev : devices ){
		string devName;
		string devOpenCLVersion;
		string devProfile;
		string devVersion;
		string driverVersion;
		std::vector<size_t> maxWorkItemSizes;
		dev.getInfo( CL_DEVICE_MAX_WORK_ITEM_SIZES, &maxWorkItemSizes );
		dev.getInfo( CL_DEVICE_NAME             , &devName );
		dev.getInfo( CL_DEVICE_OPENCL_C_VERSION , &devOpenCLVersion );
		dev.getInfo( CL_DEVICE_PROFILE          , &devProfile );
		dev.getInfo( CL_DEVICE_VERSION          , &devVersion );
		dev.getInfo( CL_DRIVER_VERSION          , &driverVersion );
		cout << "device    : " << devName       << "\n";
		cout << "OpenCl ver: " << devOpenCLVersion << "\n";
		cout << "profile   : " << devProfile    << "\n";
		cout << "device ver: " << devVersion    << "\n";
		cout << "driver ver: " << driverVersion << "\n";
		cout << "max work item sizes:";
		for( size_t size : maxWorkItemSizes )
			cout << " " << size;
		cout << "\n";
	}
}
Пример #6
0
void CLHelper::printVendor(cl::Platform platform)
{
    cl_int err;

    std::string vendorString;
    err = platform.getInfo(CL_PLATFORM_VENDOR, &vendorString);
    CHECK_OPENCL_ERROR(err, "cl::Platform::getInfo() failed.");

    std::cout << "Platform Vendor : " << vendorString << std::endl;
}
void CL_Program::printPlatformInfo(cl::Platform p)
{
    std::string platformVendor;
    std::string platformName;
    std::string platformVersion;
    std::string platformProfile;
    std::string icd_suffix;
    std::string platform_ext;
    p.getInfo((cl_platform_info)CL_PLATFORM_VENDOR, &platformVendor);
    p.getInfo((cl_platform_info)CL_PLATFORM_NAME, &platformName);
    p.getInfo((cl_platform_info)CL_PLATFORM_VERSION, &platformVersion);
    p.getInfo((cl_platform_info)CL_PLATFORM_PROFILE, &platformProfile);
    p.getInfo((cl_platform_info)CL_PLATFORM_ICD_SUFFIX_KHR, &icd_suffix);
    p.getInfo((cl_platform_info)CL_PLATFORM_EXTENSIONS, &platform_ext);
    
    std::cout << "\tVendor: " << platformVendor << "\n\tName: " << platformName << "\n\tVersion: " << platformVersion << "\n\tPlatormProfile: " << platformProfile << "\n\ticdsuffix: " << icd_suffix << "\n\tplatform extensions: " << platform_ext << std::endl;

    std::ofstream out("gpu_debug.txt", std::ios::app );
    out << "\tVendor: " << platformVendor << "\n\tName: " << platformName << "\n\tVersion: " << platformVersion << "\n\tPlatormProfile: " << platformProfile << "\n\ticdsuffix: " << icd_suffix << "\n\tplatform extensions: " << platform_ext;
    out.close();
}
Пример #8
0
void CLHelper::printDevices(cl::Platform platform, cl_device_type deviceType)
{
    cl_int err;

    std::vector<cl::Device> deviceList;
    err = platform.getDevices(deviceType, &deviceList);
    CHECK_OPENCL_ERROR(err, "cl::Platform::getDevices() failed.");

    int deviceNum;
    std::vector<cl::Device>::iterator device;
    for(deviceNum = 0, device = deviceList.begin(); device != deviceList.end(); deviceNum++, device++)
    {
    	std::string deviceName;
        err = device->getInfo(CL_DEVICE_NAME, &deviceName);
        CHECK_OPENCL_ERROR(err, "cl::Device::getInfo() failed.");

        std::cout << "Device " << deviceNum << " : " << deviceName << std::endl;
    }
}
cl::Device get_device_by_name(cl::Platform& platform, std::string name)
{
	vector<cl::Device> devices;
	platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
	if (devices.size() == 0) 
	{
		throw new std::runtime_error("No devices found");
	}
	int i = 0;
	for (auto& device : devices) {
		const string name2 = device.getInfo<CL_DEVICE_NAME>();
		const std::size_t found = name2.find(name);
		if (found != std::string::npos) 
		{
			break;
		}
		i++;
	}
	return devices[i];
}
vector<cl::Device> get_devices(cl::Platform& platform)
{
	vector<cl::Device> devices;
	platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
	return devices;
}
Пример #11
0
	CL_helper(const char *kernelFileName, std::vector<std::string> kernelNames, bool loadBinary, bool writeBinary,
				bool usePreProcArgs = false, std::map<std::string, std::string> preProcArgs = std::map<std::string, std::string>()){
		

		cl::Platform::get(&platforms);
		if(platforms.size()==0)
			throw std::runtime_error("No OpenCL platforms found.\n");

 
		int selectedPlatform=0;
		platform=platforms.at(selectedPlatform);
		platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);  
		if(devices.size()==0)
			throw std::runtime_error("No opencl devices found.\n");

		int selectedDevice=0;
		device=devices.at(selectedDevice);
		context = cl::Context(devices);

		

		try{


			if(loadBinary){
				std::string vendor=platform.getInfo<CL_PLATFORM_VENDOR>();
				size_t found = vendor.find("NVIDIA");
				if(found != std::string::npos){
					FILE* fp;
					fp = fopen("src/kernels/julia_filter.ptx", "r");
					if (!fp) {
						std::cerr << "Error loading kernel binary" << std::endl;
						std::cerr << "Building kernel from .cl file" << std::endl;
						loadBinary = false;

					} else {
						fseek(fp, 0, SEEK_END);
						size_t kernel_sz = ftell(fp);
						rewind(fp);

						char* kernel_str = (char*)malloc(kernel_sz);
						unsigned bytes = fread(kernel_str, 1, kernel_sz, fp);
						fclose(fp);

						binaries.push_back(std::make_pair((void*)kernel_str,kernel_sz+1));
				
						program = cl::Program(context, devices, binaries);	

						program.build(devices);
					}
				} else{
					std::cerr << "Vendor not NVIDIA, cannot load .ptx binary" << std::endl;
					std::cerr << "Building kernel from .cl file" << std::endl;
					loadBinary = false;
				}

			}
			if(!loadBinary){
				std::string kernelSource=CL_helper::LoadSource(kernelFileName);
				sources.push_back(std::make_pair(kernelSource.c_str(), kernelSource.size()+1)); 

				program = cl::Program(context, sources);

				if(usePreProcArgs && !preProcArgs.empty()){
					std::string preProcArgsString;
					for(auto& arg : preProcArgs) { 
						preProcArgsString += "-D" + arg.first + "=" + arg.second + " ";
					}
					program.build(devices, preProcArgsString.c_str()); 
				} else {
					//std::string params = "-cl-unsafe-math-optimizations";
					program.build(devices);
				}
			}

		}catch (cl::Error er) {
			for(unsigned i=0;i<devices.size();i++){
					std::cerr <<"Log for device " << devices[i].getInfo<CL_DEVICE_NAME>().c_str()<<std::endl;
					std::cerr << program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(devices[i]).c_str() <<std::endl;
				}
			std::cerr << "ERROR:" << er.what() << " Code " << er.err()<<std::endl;
			throw;
		}


		for(unsigned i=0; i<kernelNames.size();i++){
			kernels.push_back( cl::Kernel(program, kernelNames.at(i).c_str()) );
		}

		queue = cl::CommandQueue(context, device);


		if(writeBinary){
			size_t bin_sz;
			program.getInfo( CL_PROGRAM_BINARY_SIZES, &bin_sz);
			
			unsigned char *bin = (unsigned char *)malloc(bin_sz);
			
			program.getInfo(CL_PROGRAM_BINARIES, &bin);

			FILE* fp = fopen("src/kernels/julia_filter.ptx", "wb");
			fwrite(bin, sizeof(char), bin_sz, fp);
			fclose(fp);
			free(bin);
		}



	}