コード例 #1
0
ファイル: Event.cpp プロジェクト: jylfc0307/OpenFluidPlus
bool Event::getInfoAsString(const std::string& Key, std::string *Info) const
{
  return getInfoAsString(Key,*Info);
}
コード例 #2
0
ファイル: MSAOpenCL.cpp プロジェクト: LeiZou/ofxMSAOpenCL
	int OpenCL::getDeviceInfos(int clDeviceType) {
		cl_int err;

		cl_uint numPlatforms=0;
		err = clGetPlatformIDs( NULL, NULL, &numPlatforms ); ///< first, only fetch number of platforms.
		vector<cl_platform_id> platformIdBuffer;
		platformIdBuffer.resize(numPlatforms); /// resize to correct size

		//	windows AMD sdk/ati radeon driver implementation doesn't accept NULL as a platform ID, so fetch it first
		err = clGetPlatformIDs(	numPlatforms, platformIdBuffer.data(), NULL);
		platformIdBuffer.resize(numPlatforms);

		//	error fetching platforms... try NULL anyway
		if ( err != CL_SUCCESS || numPlatforms == 0 )
		{
			platformIdBuffer[0] = NULL;
			numPlatforms = 1;
		}

		/// a map over all platforms and devices.
		map<cl_platform_id, vector<cl_device_id> > devicesPerPlatform;

		int totalDevicesFound = 0;
		//	find first successfull platform
		// TODO: what if there is more than one platform?
		for ( int p=0;	p < numPlatforms;	p++ ) {
			cl_platform_id platformId = platformIdBuffer[p];

			// first only retrieve the number of devices.
			cl_uint numDevices=0;
			err = clGetDeviceIDs(platformId, clDeviceType, NULL, NULL, &numDevices);
			if ( err == CL_SUCCESS ) {
				//--------! invariant: numDevices now holds the numer of devices in this particular platform.
				vector<cl_device_id> deviceIds;
				deviceIds.resize(numDevices); // make sure there's enough space in there.
				/// now retrieve any device ids from the OpenCL platform into the deviceIds vector.
				err = clGetDeviceIDs(platformId, clDeviceType, numDevices, deviceIds.data(), NULL);
				if ( err == CL_SUCCESS ) {
					/// now store all found devices into the map.
					devicesPerPlatform[platformId] = deviceIds;
					totalDevicesFound += deviceIds.size();
				}
			}
		}

		// reset err.
		err = 0;

		ofLog(OF_LOG_VERBOSE, ofToString(totalDevicesFound, 0) + " devices found, on " + ofToString(numPlatforms, 0) + " platforms\n");

		//	no platforms worked
		if ( totalDevicesFound == 0) {
			ofLog(OF_LOG_ERROR, "Error finding clDevices.");
			assert(false);
			return 0;
		}	


		deviceInfo.clear();

		// now we map over all platforms and devices and collect all data we need.

		for ( map<cl_platform_id, vector<cl_device_id> >::iterator it = devicesPerPlatform.begin(); it != devicesPerPlatform.end(); it++)
		{
			vector<cl_device_id>& devices = it->second;

			for (int i = 0; i<devices.size(); i++){ 
				DeviceInfo info;

				info.clDeviceId = devices[i];  ///< store deviceID
				info.clPlatformId = it->first; ///< store platformID with device

				err = clGetDeviceInfo(info.clDeviceId, CL_DEVICE_VENDOR, sizeof(info.vendorName), info.vendorName, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_NAME, sizeof(info.deviceName), info.deviceName, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DRIVER_VERSION, sizeof(info.driverVersion), info.driverVersion, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_VERSION, sizeof(info.deviceVersion), info.deviceVersion, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(info.maxComputeUnits), &info.maxComputeUnits, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(info.maxWorkItemDimensions), &info.maxWorkItemDimensions, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_MAX_WORK_ITEM_SIZES, sizeof(info.maxWorkItemSizes), &info.maxWorkItemSizes, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(info.maxWorkGroupSize), &info.maxWorkGroupSize, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(info.maxClockFrequency), &info.maxClockFrequency, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(info.maxMemAllocSize), &info.maxMemAllocSize, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_IMAGE_SUPPORT, sizeof(info.imageSupport), &info.imageSupport, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_MAX_READ_IMAGE_ARGS, sizeof(info.maxReadImageArgs), &info.maxReadImageArgs, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, sizeof(info.maxWriteImageArgs), &info.maxWriteImageArgs, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof(info.image2dMaxWidth), &info.image2dMaxWidth, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_IMAGE2D_MAX_HEIGHT, sizeof(info.image2dMaxHeight), &info.image2dMaxHeight, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_IMAGE3D_MAX_WIDTH, sizeof(info.image3dMaxWidth), &info.image3dMaxWidth, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_IMAGE3D_MAX_HEIGHT, sizeof(info.image3dMaxHeight), &info.image3dMaxHeight, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_IMAGE3D_MAX_DEPTH, sizeof(info.image3dMaxDepth), &info.image3dMaxDepth, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_MAX_SAMPLERS, sizeof(info.maxSamplers), &info.maxSamplers, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_MAX_PARAMETER_SIZE, sizeof(info.maxParameterSize), &info.maxParameterSize, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, sizeof(info.globalMemCacheSize), &info.globalMemCacheSize, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(info.globalMemSize), &info.globalMemSize, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, sizeof(info.maxConstantBufferSize), &info.maxConstantBufferSize, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_MAX_CONSTANT_ARGS, sizeof(info.maxConstantArgs), &info.maxConstantArgs, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_LOCAL_MEM_SIZE, sizeof(info.localMemSize), &info.localMemSize, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_ERROR_CORRECTION_SUPPORT, sizeof(info.errorCorrectionSupport), &info.errorCorrectionSupport, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_PROFILING_TIMER_RESOLUTION, sizeof(info.profilingTimerResolution), &info.profilingTimerResolution, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_ENDIAN_LITTLE, sizeof(info.endianLittle), &info.endianLittle, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_PROFILE, sizeof(info.profile), info.profile, NULL);
				err |= clGetDeviceInfo(info.clDeviceId, CL_DEVICE_EXTENSIONS, sizeof(info.extensions), info.extensions, NULL);

				deviceInfo.push_back(info);

				if(err != CL_SUCCESS) {
					ofLog(OF_LOG_ERROR, "Error getting clDevice information.");
					assert(false);
				}

				ofLog(OF_LOG_VERBOSE, getInfoAsString(i));
			}
		}

		return deviceInfo.size();
	}