Exemplo n.º 1
0
	void OpenCL::setup(int clDeviceType_, int deviceNumber) {
		ofLog(OF_LOG_VERBOSE, "OpenCL::setup " + ofToString(clDeviceType_));

		if(isSetup) {
			ofLog(OF_LOG_VERBOSE, "... already setup. returning");
			return;
		}

		if(deviceInfo.size() == 0) getDeviceInfos(clDeviceType_);
		deviceNumber = (deviceNumber + getNumDevices()) % getNumDevices();
		clDevice = deviceInfo[deviceNumber].clDeviceId;

		cl_int err;
		clContext = clCreateContext(NULL, 1, &clDevice, NULL, NULL, &err);
		if(clContext == NULL) {
			ofLog(OF_LOG_ERROR, "Error creating clContext.");
			assert(err != CL_INVALID_PLATFORM);
			assert(err != CL_INVALID_VALUE);
			assert(err != CL_INVALID_DEVICE);
			assert(err != CL_INVALID_DEVICE_TYPE);
			assert(err != CL_DEVICE_NOT_AVAILABLE);
			assert(err != CL_DEVICE_NOT_FOUND);
			assert(err != CL_OUT_OF_HOST_MEMORY);
			assert(false);
		}


		createQueue();
	}	
Exemplo n.º 2
0
	void OpenCL::setupFromOpenGL(int deviceNumber) {
		ofLog(OF_LOG_VERBOSE, "OpenCL::setupFromOpenGL ");

		if(isSetup) {
			ofLog(OF_LOG_VERBOSE, "... already setup. returning");
			return;
		}

		if(deviceInfo.size() == 0) getDeviceInfos(CL_DEVICE_TYPE_GPU);
		deviceNumber = (deviceNumber + getNumDevices()) % getNumDevices();
		clDevice = deviceInfo[deviceNumber].clDeviceId;
		cl_platform_id clPlatformID = deviceInfo[deviceNumber].clPlatformId;

		cl_int err;

#ifdef TARGET_OSX	
		CGLContextObj kCGLContext = CGLGetCurrentContext();
		CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext);
		cl_context_properties properties[] = { CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)kCGLShareGroup, 0 };

		clContext = clCreateContext(properties, 0, 0, NULL, NULL, &err);
#elif defined _WIN32
		//aqcuire shared context on windows.
		{
			// TODO: we want to be more specific about the platform,
			// at the moment only the first successful platform is selected. 

			cl_context_properties properties[] = 
			{
				CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(), 
				CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(), 
				CL_CONTEXT_PLATFORM, (cl_context_properties)clPlatformID, 
				0
			};
			ofLogNotice() << "Using OpenCL Platform: 0x" << std::hex << clPlatformID;
			ofLogNotice() << "Using OpenCL Device: 0x" << std::hex << clDevice;

			clContext = clCreateContext(properties, 1, &clDevice, NULL, NULL, &err);
			ofLogNotice() <<  "Created OpenCL context: " << (err == CL_SUCCESS ? "SUCCESS" : "ERROR");
		}

#endif
		if(clContext == NULL) {
			ofLog(OF_LOG_ERROR, "Error creating clContext.");
			assert(err != CL_INVALID_PLATFORM);
			assert(err != CL_INVALID_VALUE);
			assert(err != CL_INVALID_DEVICE);
			assert(err != CL_INVALID_DEVICE_TYPE);
			assert(err != CL_DEVICE_NOT_AVAILABLE);
			assert(err != CL_DEVICE_NOT_FOUND);
			assert(err != CL_OUT_OF_HOST_MEMORY);
			assert(false);
		}

		createQueue();
	}	
Exemplo n.º 3
0
//----------------------------------------------------------------------------//
void SoundDevices::resetFilters()
{
	for (int i = 0; i < getNumDevices(); i++) {
		vDeviceInfo[i].bSelected = true;
	}
	filterIndex = 0;
}
Exemplo n.º 4
0
//----------------------------------------------------------------------------//
unsigned int SoundDevices::getMaxNumSources(int index) const
{
	if (index < getNumDevices())
		return vDeviceInfo[index].uiSourceCount;
	else
		return 0;
}
Exemplo n.º 5
0
//----------------------------------------------------------------------------//
char * SoundDevices::getDeviceName(int index) const
{
	if (index < getNumDevices())
		return (char *)vDeviceInfo[index].strDeviceName.c_str();
	else
		return nullptr;
}
Exemplo n.º 6
0
void SpiShield::init()
{
	SPI.begin();

	const uint8_t n = getNumDevices();
	for (uint8_t i=0; i<n; ++i)
	{
		getDevice(i)->init();
	}
}
Exemplo n.º 7
0
//----------------------------------------------------------------------------//
void SoundDevices::getDeviceVersion(int index, int *major, int *minor) const
{
	if (index < getNumDevices()) {
		if (major)
			*major = vDeviceInfo[index].iMajorVersion;
		if (minor)
			*minor = vDeviceInfo[index].iMinorVersion;
	}
	return;
}
Exemplo n.º 8
0
//----------------------------------------------------------------------------//
int SoundDevices::getNextFilteredDevice()
{
	int i;

	for (i = filterIndex; i < getNumDevices(); i++) {
		if (vDeviceInfo[i].bSelected == true) {
			break;
		}
	}
	filterIndex = i + 1;
	return i;
}
Exemplo n.º 9
0
void SpiShield::update()
{
	const uint8_t n = getNumDevices();
	for (uint8_t i=0; i<n; ++i)
	{
		SpiDevice *device = getDevice(i);

		if (!device)
			continue;

		device->update();
	}
}
Exemplo n.º 10
0
//----------------------------------------------------------------------------//
int SoundDevices::getDeviceIndex(const char* DeviceName) const
{
	int index = -1;
	for (int i = 0; i < getNumDevices(); i++) 
	{
		if (strcmp(getDeviceName(i), DeviceName) == 0) 
		{
			index = i;
			break;
		}
	}
	return index;
}
Exemplo n.º 11
0
	string OpenCL::getInfoAsString(int deviceNumber) {
		deviceNumber = (deviceNumber + getNumDevices()) % getNumDevices();

		DeviceInfo &info = deviceInfo[deviceNumber];
		return string("\n\n*********\nOpenCL Device information for device #") + ofToString(deviceNumber) +
			"\n cl_device_id................" + ofToString(info.clDeviceId) +
			"\n vendorName.................." + string((char*)info.vendorName) + 
			"\n deviceName.................." + string((char*)info.deviceName) + 
			"\n driverVersion..............." + string((char*)info.driverVersion) +
			"\n deviceVersion..............." + string((char*)info.deviceVersion) +
			"\n maxComputeUnits............." + ofToString(info.maxComputeUnits, 0) +
			"\n maxWorkItemDimensions......." + ofToString(info.maxWorkItemDimensions, 0) +
			"\n maxWorkItemSizes[0]........." + ofToString(info.maxWorkItemSizes[0], 0) + 
			"\n maxWorkGroupSize............" + ofToString(info.maxWorkGroupSize, 0) +
			"\n maxClockFrequency..........." + ofToString(info.maxClockFrequency, 0) +
			"\n maxMemAllocSize............." + ofToString(info.maxMemAllocSize/1024.0f/1024.0f, 3) + " MB" + 
			"\n imageSupport................" + (info.imageSupport ? "YES" : "NO") +
			"\n maxReadImageArgs............" + ofToString(info.maxReadImageArgs, 0) +
			"\n maxWriteImageArgs..........." + ofToString(info.maxWriteImageArgs, 0) +
			"\n image2dMaxWidth............." + ofToString(info.image2dMaxWidth, 0) +
			"\n image2dMaxHeight............" + ofToString(info.image2dMaxHeight, 0) +
			"\n image3dMaxWidth............." + ofToString(info.image3dMaxWidth, 0) +
			"\n image3dMaxHeight............" + ofToString(info.image3dMaxHeight, 0) +
			"\n image3dMaxDepth............." + ofToString(info.image3dMaxDepth, 0) +
			"\n maxSamplers................." + ofToString(info.maxSamplers, 0) +
			"\n maxParameterSize............" + ofToString(info.maxParameterSize, 0) +
			"\n globalMemCacheSize.........." + ofToString(info.globalMemCacheSize/1024.0f/1024.0f, 3) + " MB" + 
			"\n globalMemSize..............." + ofToString(info.globalMemSize/1024.0f/1024.0f, 3) + " MB" +
			"\n maxConstantBufferSize......." + ofToString(info.maxConstantBufferSize/1024.0f, 3) + " KB"
			"\n maxConstantArgs............." + ofToString(info.maxConstantArgs, 0) +
			"\n localMemSize................" + ofToString(info.localMemSize/1024.0f, 3) + " KB"
			"\n errorCorrectionSupport......" + (info.errorCorrectionSupport ? "YES" : "NO") +
			"\n profilingTimerResolution...." + ofToString(info.profilingTimerResolution, 0) +
			"\n endianLittle................" + ofToString(info.endianLittle, 0) +
			"\n profile....................." + string((char*)info.profile) +
			"\n extensions.................." + string((char*)info.extensions) +
			"\n*********\n\n";
	}
Exemplo n.º 12
0
int init_mandelbrot ()
{
  int i;
  cl_int error;

  if (mandelbrot_init)
    return 1;

  context = get_cl_context();
  device = get_cl_device();

  FILE *fp;
  fp = fopen(CLKERNELDEFS, "r");
  if (!fp) {
    fprintf(stderr, "Failed to load kernel.\n");
    return(1);
  }
  char *src = (char*) malloc (MAX_SOURCE_SIZE);
  size_t srcsize = fread (src, 1, MAX_SOURCE_SIZE, fp);
  fclose (fp);
  const char *srcptr[]={src};

  // get the number of GPUS/DEVICES available
  numdevices = getNumDevices();

#if CAN_USE_DOUBLE
  // build CL program with a USE_DOUBLE define if we found the correct extension
  if (getCorrectDevice("cl_khr_fp64") == CL_SUCCESS) {
    error = buildcl (srcptr, &srcsize, &prog[0], "-D USE_DOUBLE -cl-fast-relaxed-math -cl-mad-enable", numdevices);
  }
  else {
#endif
    mandelbrot_cl_float = 1;
    error = buildcl (srcptr, &srcsize, &prog[0], "-D USE_FLOAT -cl-fast-relaxed-math -cl-mad-enable", numdevices);
#if CAN_USE_DOUBLE
  }
#endif
  // create kernel
  for (i=0; i<numdevices; i++) {
    k_mandelbrot[i] = clCreateKernel(prog[i], "mandelbrot", &error);
  }
  // get the shared CQ
  cq = get_command_queue();

  if (!error)
    mandelbrot_init = 1;

  return error;
}
Exemplo n.º 13
0
//----------------------------------------------------------------------------//
bool SoundDevices::isExtensionSupported(int index, char *szExtName) const
{
	bool bReturn = false;

	if (index < getNumDevices()) {
		for (unsigned int i = 0; i < vDeviceInfo[index].pvstrExtensions->size(); i++) {
			if (!_stricmp(vDeviceInfo[index].pvstrExtensions->at(i).c_str(), szExtName)) {
				bReturn = true;
				break;
			}				
		}
	}

	return bReturn;
}
Exemplo n.º 14
0
vector<string> D2xxSerial::getDeviceSerialNumbers() {
	
	vector<string> devices;
	FT_STATUS ftStatus;
	DWORD numDevs = getNumDevices();
	
	for(int i = 0; i < numDevs; i++) {
		DWORD devIndex = i;
		char Buffer[16];
		ftStatus = FT_ListDevices((PVOID)devIndex,Buffer,FT_LIST_BY_INDEX|FT_OPEN_BY_SERIAL_NUMBER);
		if (FT_SUCCESS(ftStatus)) {
			// FT_ListDevices OK, serial number is in Buffer
			
			devices.push_back(string(Buffer));
		} else {
			devices.push_back("error");
			// FT_ListDevices failed
			printf("Couldn't get serial number of device [%d] - error: %s\n", i, getError(ftStatus));
		}
	}
	return devices;
	
}
Exemplo n.º 15
0
int init_mandelbrotvis ()
{
  int i;
  cl_int error;

  if (mandelbrotvis_init)
    return 1;

  context = get_cl_context();
  device = get_cl_device();

  FILE *fp;
  fp = fopen(CLVISKERNELDEFS, "r");
  if (!fp) {
    fprintf(stderr, "Failed to load kernel.\n");
    return(1);
  }
  char *src = (char*) malloc (MAX_SOURCE_SIZE);
  size_t srcsize = fread (src, 1, MAX_SOURCE_SIZE, fp);
  fclose (fp);
  const char *srcptr[]={src};

  // get the number of GPUS/DEVICES available
  numdevices = getNumDevices();

  // build CL program with a USE_DOUBLE define if we found the correct extension
  char *precision = "             ";
#if CAN_USE_DOUBLE
  if (getCorrectDevice("cl_khr_fp64") == CL_SUCCESS) {
    precision = "-D USE_DOUBLE";
  }
  else {
#endif
    mandelbrot_cl_float = 1;
    precision = "-D USE_FLOAT";
#if CAN_USE_DOUBLE
  }
#endif

  char options[MAX_BUILD_LINE_LENGTH];
  // following options seem to speed things up a little
  char *compile_opt = "-cl-fast-relaxed-math -cl-mad-enable";
  snprintf(options, MAX_BUILD_LINE_LENGTH,
           "%s -D IMAGEWIDTHVIS=%d -D IMAGEHEIGHTVIS=%d %s", precision, viswidth, visheight, compile_opt);
  error = buildcl (srcptr, &srcsize, &progvis[0], options, numdevices);
//  printf("%s\n\n\n", options);

  // create kernel
  for (i=0; i<numdevices; i++) {
    k_mandelbrotvis[i] = clCreateKernel(progvis[i], "mandelbrot_vis", &error);
  }
  // get the shared CQ
  cq = get_command_queue();

  // initialise the jobs array
  initialiseJobs();

  if (!error)
    mandelbrotvis_init = 1;

  return error;
}