Example #1
0
void OpenCL::init(int isGPU)
{
	if (isGPU)
		getDevices(CL_DEVICE_TYPE_GPU);
	else
		getDevices(CL_DEVICE_TYPE_CPU);

	buildKernel();
}
Example #2
0
int kickstartFromRemovable(char *kssrc) {
    struct device ** devices;
    char *p, *kspath;
    int i, rc;

    logMessage(INFO, "doing kickstart from removable media");
    devices = getDevices(DEVICE_DISK);
    /* usb can take some time to settle, even with the various hacks we
     * have in place. some systems use portable USB CD-ROM drives, try to
     * make sure there really isn't one before bailing. */
    for (i = 0; !devices && i < 10; ++i) {
        logMessage(INFO, "sleeping to wait for a USB disk");
        sleep(2);
        devices = getDevices(DEVICE_DISK);
    }
    if (!devices) {
        logMessage(ERROR, "no disks");
        return 1;
    }

    for (i = 0; devices[i]; i++) {
        if (devices[i]->priv.removable == 1) {
            logMessage(INFO, "first removable media is %s", devices[i]->device);
            break;
        }
    }

    if (!devices[i] || (devices[i]->priv.removable == 0)) {
        logMessage(ERROR, "no removable devices");
        return 1;
    }

    /* format is floppy:[/path/to/ks.cfg] */
    kspath = "";
    p = strchr(kssrc, ':');
    if (p)
	kspath = p + 1;

    if (!p || strlen(kspath) < 1)
	kspath = "/ks.cfg";

    if ((rc=getKickstartFromBlockDevice(devices[i]->device, kspath))) {
	if (rc == 3) {
	    startNewt();
	    newtWinMessage(_("Error"), _("OK"),
			   _("Cannot find ks.cfg on removable media."));
	}
	return 1;
    }

    return 0;
}
void MidiSession::openOutputDevice(std::string device)
{
    auto numMidiInputs = Pm_CountDevices();
    auto devices = getDevices();
    
    for(auto i = 0; i < numMidiInputs; i++)
    {
        if(devices[i] == device)
        {
            if(!Pm_GetDeviceInfo(i)->opened)
                error = Pm_OpenOutput(&midiStream, i, nullptr, 3, nullptr, nullptr, 0);
            else
                std::cout<<"Device is already opened"<<std::endl;
            
            if(error != pmNoError)
            {
                std::cout<<"Trying to open device: "<<devices[i]<<std::endl;
                std::cout<<Pm_GetErrorText(error)<<std::endl;
                return;
            }
            
            midiThread = std::thread(&MidiSession::read, this);
            midiThread.detach();
            
            return;
        }
    }
}
Example #4
0
/*
	Name		DirectInput::DirectInput
	Syntax		DirectInput()
	Brief		DirectInput constructor gets the input devices and initialises input variables
*/
DirectInput::DirectInput()
: diObject_(0), keyboardDevice_(0), mouseDevice_(0), mouseX_(0), mouseY_(0), mouseZ_(0),
  mouseLeftUp_(true), mouseLeftDown_(false), mouseRightUp_(true), mouseRightDown_(false),
  mouseLeftPressed_(false), mouseRightPressed_(false), KEYBOARD_BUFFER_SIZE(16)
{ 
    if (!getDevices())
    {
        throw new std::exception("getDevices failed.");
    }

    // Initialise the key events arrays
    for (int i = 0; i < 256; ++i)
    {
        heldKeys_[i] = false;
    }

	for (int i = 0; i < 256; ++i)
    {
        pressedKeys_[i] = false;
    }

	// Initialise the mouse button flags
	mouseLeftUp_ = true;
	mouseLeftDown_ = false;
	mouseRightUp_ = true;
	mouseRightDown_ = false;
	mouseLeftPressed_ = false;
	mouseRightPressed_ = false;
}
Example #5
0
int
main(int argc, const char *argv[])
{
  char **ppsz_cd_drives=NULL, **c;
  
  cdio_log_set_handler (log_handler);

  /* Print out a list of CD-drives */
  printf("All CD-ROM/DVD drives...\n");
  ppsz_cd_drives = getDevices();
  if (NULL != ppsz_cd_drives) 
    for( c = ppsz_cd_drives; *c != NULL; c++ ) {
      printf("Drive %s\n", *c);
    }

  freeDeviceList(ppsz_cd_drives);

  print_drive_class("All CD-ROM drives (again)", CDIO_FS_MATCH_ALL);
  print_drive_class("CD-ROM drives with a CD-DA loaded...", CDIO_FS_AUDIO);
  print_drive_class("CD-ROM drives with some sort of ISO 9660 filesystem...", 
		    CDIO_FS_ANAL_ISO9660_ANY, true);
  print_drive_class("(S)VCD drives...", CDIO_FS_ANAL_VCD_ANY, true);
  return 0;
  
}
Example #6
0
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);
}
Example #7
0
static ENGINE *engine_qat(void)
{
    ENGINE *ret = NULL;
    unsigned int devmasks[] = { 0, 0, 0 };
    DEBUG("[%s] engine_qat\n", __func__);

    if (access(QAT_DEV, F_OK) != 0) {
        QATerr(QAT_F_ENGINE_QAT, QAT_R_MEM_DRV_NOT_PRESENT);
        return ret;
    }

    if (!getDevices(devmasks)) {
        QATerr(QAT_F_ENGINE_QAT, QAT_R_QAT_DEV_NOT_PRESENT);
        return ret;
    }

    ret = ENGINE_new();

    if (!ret)
        return NULL;

    if (!bind_qat(ret, engine_qat_id)) {
        WARN("qat engine bind failed!\n");
        ENGINE_free(ret);
        return NULL;
    }

    return ret;
}
Example #8
0
void CubicSDR::setOffset(long long ofs) {
    offset = ofs;
    SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_SET_OFFSET);
    command.llong_value = ofs;
    pipeSDRCommand->push(command);
    
    SDRDeviceInfo *dev = (*getDevices())[getDevice()];
    config.getDevice(dev->getDeviceId())->setOffset(ofs);
}
Example #9
0
DeviceRef DeviceManager::findDeviceByKey( const string &key )
{
	for( const auto &device : getDevices() ) {
		if( device->getKey() == key )
			return device;
	}

	return DeviceRef();
}
Example #10
0
DeviceRef DeviceManager::findDeviceByName( const string &name )
{
	for( const auto &device : getDevices() ) {
		if( device->getName() == name )
			return device;
	}

	return DeviceRef();
}
Example #11
0
void CubicSDR::setDirectSampling(int mode) {
    directSamplingMode = mode;
    SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_SET_DIRECT_SAMPLING);
    command.llong_value = mode;
    pipeSDRCommand->push(command);

    SDRDeviceInfo *dev = (*getDevices())[getDevice()];
    config.getDevice(dev->getDeviceId())->setDirectSampling(mode);
}
Example #12
0
InputDeviceRef Input::findDeviceByNameContains( const std::string &nameFragment )
{
	const std::vector<InputDeviceRef>& devices = getDevices();
	for (size_t i = 0; i < devices.size(); ++i) {
		if (devices[i]->getName().find(nameFragment) != std::string::npos)
			return devices[i];
	}
	return InputDeviceRef();
}
Example #13
0
InputDeviceRef Input::findDeviceByName( const std::string &name )
{
	const std::vector<InputDeviceRef>& devices = getDevices();
	for (size_t i = 0; i < devices.size(); ++i) {
		if (devices[i]->getName() == name)
			return devices[i];
	}
	return InputDeviceRef();
}
Example #14
0
Serial::Device Serial::findDeviceByName( const std::string &name, bool forceRefresh )
{
	const std::vector<Serial::Device> &devices = getDevices( forceRefresh );
	for( std::vector<Serial::Device>::const_iterator deviceIt = devices.begin(); deviceIt != devices.end(); ++deviceIt ) {
		if( deviceIt->getName() == name )
			return *deviceIt;
	}
	
	return Serial::Device();
}
Example #15
0
Serial::Device Serial::findDeviceByNameContains( const std::string &searchString, bool forceRefresh )
{
	const std::vector<Serial::Device> &devices = getDevices( forceRefresh );
	for( std::vector<Serial::Device>::const_iterator deviceIt = devices.begin(); deviceIt != devices.end(); ++deviceIt ) {
		if( deviceIt->getName().find( searchString ) != std::string::npos )
			return *deviceIt;
	}
	
	return Serial::Device();
}
Example #16
0
vector<DeviceRef> Device::getInputDevices()
{
	vector<DeviceRef> result;
	for( const auto &dev : getDevices() ) {
		if( dev->getNumInputChannels() > 0 )
			result.push_back( dev );
	}

	return result;
}
Example #17
0
int CubicSDR::getPPM() {
    if (sdrThread->getDeviceId() < 0) {
        return 0;
    }
    SDRDeviceInfo *dev = (*getDevices())[getDevice()];

    SDRThreadCommand command_ppm(SDRThreadCommand::SDR_THREAD_CMD_SET_PPM);
    ppm = config.getDevice(dev->getDeviceId())->getPPM();

    return ppm;
}
Example #18
0
void
Studio::
resyncDeviceConnections(void)
{
    // Sync all the device connections
    DeviceList *devices = getDevices();
    for (uint i = 0; i < devices->size(); ++i) {
        DeviceId id = (*devices)[i]->getId();
        QString connection = RosegardenSequencer::getInstance()->getConnection(id);
        (*devices)[i]->setConnection(qstrtostr(connection));
    }
}
Example #19
0
string Device::printDevicesToString()
{
	stringstream stream;

	for( auto &device : getDevices() ) {
		stream << "-- " << device->getName() << " --" << endl;
		stream << "\t key: " << device->getKey() << endl;
		stream << "\t inputs: " << device->getNumInputChannels() << ", outputs: " << device->getNumOutputChannels() << endl;
		stream << "\t samplerate: " << device->getSampleRate() << ", frames per block: " << device->getFramesPerBlock() << endl;
	}

	return stream.str();
}
Example #20
0
bool startApp( AppCtx *appCtx, WstCompositor *wctx )
{
   bool result= false;
   
   if ( appCtx )
   {
      appCtx->wctx= wctx;
      
      #if !defined (WESTEROS_PLATFORM_EMBEDDED)
      WstCompositorSetNativeWindow( appCtx->wctx, appCtx->nativeWindow );
      #endif
      
      if ( !WstCompositorGetIsNested( appCtx->wctx ) )
      {
         #if defined (WESTEROS_PLATFORM_EMBEDDED)
         InputCtx *inputCtx= appCtx->inputCtx;
         
         getDevices( inputCtx->deviceFds );
         if ( inputCtx->deviceFds.size() > 0 )
         {
            inputCtx->wctx= wctx;
            int rc= pthread_create( &appCtx->inputThreadId, NULL, inputThread, inputCtx );
            if ( rc )
            {
               printf("unable to start input thread: error %d\n", rc );
            }
         }
         #else
         WstCompositorPointerEnter( appCtx->wctx );
         #endif
      }
      
      if ( appCtx->isEmbedded )
      {
         appCtx->matrix[0]= 1.0f;
         appCtx->matrix[5]= 1.0f;
         appCtx->matrix[10]= 1.0f;
         appCtx->matrix[15]= 1.0f;
         appCtx->x= 0;
         appCtx->y= 0;
         appCtx->width= 1280;
         appCtx->height= 720;
         
         appCtx->alpha= 1.0f;
      }
      
      result= true;
   }
   
   return result;
}
Example #21
0
void CubicSDR::setDevice(int deviceId) {
    sdrThread->setDeviceId(deviceId);
    SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_SET_DEVICE);
    command.llong_value = deviceId;
    pipeSDRCommand->push(command);

    SDRDeviceInfo *dev = (*getDevices())[deviceId];
    DeviceConfig *devConfig = config.getDevice(dev->getDeviceId());

    setPPM(devConfig->getPPM());
    setDirectSampling(devConfig->getDirectSampling());
    setSwapIQ(devConfig->getIQSwap());
    setOffset(devConfig->getOffset());
}
Example #22
0
void CubicSDR::setPPM(int ppm_in) {
    if (sdrThread->getDeviceId() < 0) {
        return;
    }
    ppm = ppm_in;

    SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_SET_PPM);
    command.llong_value = ppm;
    pipeSDRCommand->push(command);

    SDRDeviceInfo *dev = (*getDevices())[getDevice()];

    config.getDevice(dev->getDeviceId())->setPPM(ppm_in);
}
Example #23
0
static void 
print_drive_class(const char *psz_msg, cdio_fs_anal_t bitmask, 
		  bool b_any=false) {
  char **ppsz_cd_drives=NULL, **c;

  printf("%s...\n", psz_msg);
  ppsz_cd_drives = getDevices(NULL,  bitmask, b_any);
  if (NULL != ppsz_cd_drives) 
    for( c = ppsz_cd_drives; *c != NULL; c++ ) {
      printf("Drive %s\n", *c);
    }

  freeDeviceList(ppsz_cd_drives);
  printf("-----\n");
}
Example #24
0
Common::Error WindowsMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle dev) const {
	int devIndex = 0;
	bool found = false;

	if (dev) {
		MusicDevices i = getDevices();
		for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
			if (d->getCompleteId().equals(MidiDriver::getDeviceString(dev, MidiDriver::kDeviceId))) {
				found = true;
				break;
			}
			devIndex++;
		}
	}

	*mididriver = new MidiDriver_WIN(found ? devIndex : 0);
	return Common::kNoError;
}
Example #25
0
int checkLimitDevAccessValue(int *limitDevAccess, char *section_name)
{
    unsigned int devmasks[] = { 0, 0, 0 };
    char *dev_names[] = { DH89XXCC_NAME, DH895XCC_NAME, C2XXX_NAME };
    char configFilePath[CONF_MAX_PATH];
    char configKeyValue[CONF_MAX_LINE_LENGTH] = { 0 };
    int configKeyValueSize = CONF_MAX_LINE_LENGTH;
    int status;
    int i, j;
    if (!getDevices(devmasks)) {
        *limitDevAccess = 0;
        return 0;
    }
    for (j = 0; j < NUM_DEVICES_TYPES; j++)
        for (i = 0; i < MAX_NUM_DEVICES; i++) {
            if ((devmasks[j] & (1 << i))) {
                sprintf(configFilePath, "/etc/%s_qa_dev%d.conf", dev_names[j],
                        i);
            } else {
                continue;
            }
            DEBUG("looking in %s\n", configFilePath);
            status = confCryptoFindKeyValue(configFilePath, section_name,
                                            "LimitDevAccess", configKeyValue,
                                            configKeyValueSize);
            if (status == CONF_FIND_KEY_SECTION_FOUND) {
                /* if the SHIM section was found in the config file but no
                   LimitDevAccess setting,
                   LimitDevAccess is set to 0 */
                *limitDevAccess = 0;
                return 1;
            } else if (status == CONF_FIND_KEY_KEY_FOUND) {
                if (isdigit(configKeyValue[0])) {
                    *limitDevAccess = atoi(configKeyValue);
                    return 1;
                }
            }
        }
    *limitDevAccess = 0;
    return 0;
}
Example #26
0
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;
}
Example #27
0
string V4L::getFrameGrabberOptions() {

    string tmp = "Devices;";
    vector<string>::iterator iter1;
    vector<string> devices = getDevices();
    /*przekazanie urzadzen*/
    for (iter1 = devices.begin(); iter1 != devices.end(); iter1++)
        tmp = tmp + (*iter1) + ";";
    tmp = tmp + ";Channels;";

    /*przekazanie kanalow*/
    vector<string> channels = getChannels();
    for (iter1 = channels.begin(); iter1 != channels.end(); iter1++)
        tmp = tmp + (*iter1) + ";";
    tmp = tmp + ";Palettes;";

    vector<string> palettes = getPalettes();
    for (iter1 = palettes.begin(); iter1 != palettes.end(); iter1++)
        tmp = tmp + (*iter1) + ";";
    tmp = tmp + ";Width;";

    vector<string> width = getWidth();
    for (iter1 = width.begin(); iter1 != width.end(); iter1++)
        tmp = tmp + (*iter1) + ";";
    tmp = tmp + ";Height;";

    vector<string> height = getHeight();
    for (iter1 = height.begin(); iter1 != height.end(); iter1++)
        tmp = tmp + (*iter1) + ";";
    tmp = tmp + ";Standard;";

    vector<string> standard = getStandard();
    for (iter1 = standard.begin(); iter1 != standard.end(); iter1++)
        tmp = tmp + (*iter1) + ";";

    cout << "poszlo" << endl;
    return tmp;
}
int AtomicCounters::setupCL(void) {
  cl_int status = 0;
  cl_device_type dType;
  if (sampleArgs->deviceType.compare("cpu") == 0) {
    dType = CL_DEVICE_TYPE_CPU;
  } else  // deviceType = "gpu"
  {
    dType = CL_DEVICE_TYPE_GPU;
    if (sampleArgs->isThereGPU() == false) {
      std::cout << "GPU not found. Falling back to CPU" << std::endl;
      dType = CL_DEVICE_TYPE_CPU;
    }
  }
  cl_platform_id platform = NULL;
  int retValue = getPlatform(platform, sampleArgs->platformId,
                             sampleArgs->isPlatformEnabled());
  CHECK_ERROR(retValue, SDK_SUCCESS, "getPlatform() failed.");
  // Display available devices.
  retValue = displayDevices(platform, dType);
  CHECK_ERROR(retValue, SDK_SUCCESS, "displayDevices() failed.");
  cl_context_properties cps[3] = {CL_CONTEXT_PLATFORM,
                                  (cl_context_properties)platform, 0};
  context = clCreateContextFromType(cps, dType, NULL, NULL, &status);
  CHECK_OPENCL_ERROR(status, "clCreateContextFromType failed.");
  // getting device on which to run the sample
  status = getDevices(context, &devices, sampleArgs->deviceId,
                      sampleArgs->isDeviceIdEnabled());
  CHECK_ERROR(status, SDK_SUCCESS, "getDevices() failed ");
  // Set device info of given cl_device_id
  retValue = deviceInfo.setDeviceInfo(devices[sampleArgs->deviceId]);
  CHECK_ERROR(retValue, SDK_SUCCESS, "SDKDeviceInfo::setDeviceInfo() failed");
  // Check device extensions
  if (!strstr(deviceInfo.extensions, "cl_ext_atomic_counters_32")) {
    OPENCL_EXPECTED_ERROR(
        "Device does not support cl_ext_atomic_counters_32 extension!");
  }
  if (!strstr(deviceInfo.extensions, "cl_khr_local_int32_base_atomics")) {
    OPENCL_EXPECTED_ERROR(
        "Device does not support cl_khr_local_int32_base_atomics extension!");
  }
  // Get OpenCL device version
  std::string deviceVersionStr = std::string(deviceInfo.deviceVersion);
  size_t vStart = deviceVersionStr.find(" ", 0);
  size_t vEnd = deviceVersionStr.find(" ", vStart + 1);
  std::string vStrVal = deviceVersionStr.substr(vStart + 1, vEnd - vStart - 1);
// Check of OPENCL_C_VERSION if device version is 1.1 or later
#ifdef CL_VERSION_1_1
  if (deviceInfo.openclCVersion) {
    // Exit if OpenCL C device version is 1.0
    deviceVersionStr = std::string(deviceInfo.openclCVersion);
    vStart = deviceVersionStr.find(" ", 0);
    vStart = deviceVersionStr.find(" ", vStart + 1);
    vEnd = deviceVersionStr.find(" ", vStart + 1);
    vStrVal = deviceVersionStr.substr(vStart + 1, vEnd - vStart - 1);
    if (vStrVal.compare("1.0") <= 0) {
      OPENCL_EXPECTED_ERROR(
          "Unsupported device! Required CL_DEVICE_OPENCL_C_VERSION as 1.1");
    }
  } else {
    OPENCL_EXPECTED_ERROR(
        "Unsupported device! Required CL_DEVICE_OPENCL_C_VERSION as 1.1");
  }
#else
  OPENCL_EXPECTED_ERROR(
      "Unsupported device! Required CL_DEVICE_OPENCL_C_VERSION as 1.1");
#endif
  // Setup application data
  if (setupAtomicCounters() != SDK_SUCCESS) {
    return SDK_FAILURE;
  }
  cl_command_queue_properties props = CL_QUEUE_PROFILING_ENABLE;
  commandQueue = clCreateCommandQueue(context, devices[sampleArgs->deviceId],
                                      props, &status);
  CHECK_OPENCL_ERROR(status, "clCreateCommandQueue failed(commandQueue)");
  // Set Persistent memory only for AMD platform
  cl_mem_flags inMemFlags = CL_MEM_READ_ONLY;
  if (sampleArgs->isAmdPlatform()) {
    inMemFlags |= CL_MEM_USE_PERSISTENT_MEM_AMD;
  }
  // Create buffer for input array
  inBuf = clCreateBuffer(context, inMemFlags, length * sizeof(cl_uint), NULL,
                         &status);
  CHECK_OPENCL_ERROR(status, "clCreateBuffer failed.(inBuf)");
  // Set up data for input array
  cl_event writeEvt;
  status =
      clEnqueueWriteBuffer(commandQueue, inBuf, CL_FALSE, 0,
                           length * sizeof(cl_uint), input, 0, NULL, &writeEvt);
  CHECK_OPENCL_ERROR(status, "clEnqueueWriteBuffer(inBuf) failed..");
  status = clFlush(commandQueue);
  CHECK_OPENCL_ERROR(status, "clFlush(commandQueue) failed.");
  counterOutBuf = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_uint),
                                 NULL, &status);
  CHECK_OPENCL_ERROR(status, "clCreateBuffer failed.(counterOutBuf).");
  globalOutBuf = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_uint),
                                NULL, &status);
  CHECK_OPENCL_ERROR(status, "clCreateBuffer failed.(globalOutBuf).");
  // create a CL program using the kernel source
  buildProgramData buildData;
  buildData.kernelName = std::string("AtomicCounters_Kernels.cl");
  buildData.devices = devices;
  buildData.deviceId = sampleArgs->deviceId;
  buildData.flagsStr = std::string("");
  if (sampleArgs->isLoadBinaryEnabled()) {
    buildData.binaryName = std::string(sampleArgs->loadBinary.c_str());
  }
  if (sampleArgs->isComplierFlagsSpecified()) {
    buildData.flagsFileName = std::string(sampleArgs->flags.c_str());
  }
  retValue = buildOpenCLProgram(program, context, buildData);
  CHECK_ERROR(retValue, SDK_SUCCESS, "buildOpenCLProgram() failed");
  // ConstantBuffer bandwidth from single access
  counterKernel = clCreateKernel(program, "atomicCounters", &status);
  CHECK_OPENCL_ERROR(status, "clCreateKernel failed.(counterKernel).");
  globalKernel = clCreateKernel(program, "globalAtomics", &status);
  CHECK_OPENCL_ERROR(status, "clCreateKernel(globalKernel) failed.");
  status = kernelInfoC.setKernelWorkGroupInfo(counterKernel,
                                              devices[sampleArgs->deviceId]);
  CHECK_OPENCL_ERROR(status, "kernelInfo.setKernelWorkGroupInfo failed");
  status = kernelInfoG.setKernelWorkGroupInfo(globalKernel,
                                              devices[sampleArgs->deviceId]);
  CHECK_OPENCL_ERROR(status, "kernelInfo.setKernelWorkGroupInfo failed");
  if (counterWorkGroupSize > kernelInfoC.kernelWorkGroupSize) {
    if (!sampleArgs->quiet) {
      std::cout << "Out of Resources!" << std::endl;
      std::cout << "Group Size specified : " << counterWorkGroupSize
                << std::endl;
      std::cout << "Max Group Size supported on the kernel(readKernel) : "
                << kernelInfoC.kernelWorkGroupSize << std::endl;
      std::cout << "Falling back to " << kernelInfoC.kernelWorkGroupSize
                << std::endl;
    }
    counterWorkGroupSize = kernelInfoC.kernelWorkGroupSize;
  }
  if (globalWorkGroupSize > kernelInfoG.kernelWorkGroupSize) {
    if (!sampleArgs->quiet) {
      std::cout << "Out of Resources!" << std::endl;
      std::cout << "Group Size specified : " << globalWorkGroupSize
                << std::endl;
      std::cout << "Max Group Size supported on the kernel(writeKernel) : "
                << kernelInfoG.kernelWorkGroupSize << std::endl;
      std::cout << "Falling back to " << kernelInfoG.kernelWorkGroupSize
                << std::endl;
    }
    globalWorkGroupSize = kernelInfoG.kernelWorkGroupSize;
  }
  // Wait for event and release event
  status = waitForEventAndRelease(&writeEvt);
  CHECK_OPENCL_ERROR(status, "waitForEventAndRelease(writeEvt) failed.");
  return SDK_SUCCESS;
}
Example #29
0
/**
 * Process any relevant changes in the attached USB devices.
 *
 * Except for the first call, this is always running on the service thread.
 */
void USBProxyService::processChanges(void)
{
    LogFlowThisFunc(("\n"));

    /*
     * Get the sorted list of USB devices.
     */
    PUSBDEVICE pDevices = getDevices();
    pDevices = sortDevices(pDevices);

    // get a list of all running machines while we're outside the lock
    // (getOpenedMachines requests higher priority locks)
    SessionMachinesList llOpenedMachines;
    mHost->parent()->getOpenedMachines(llOpenedMachines);

    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);

    /*
     * Compare previous list with the new list of devices
     * and merge in any changes while notifying Host.
     */
    HostUSBDeviceList::iterator it = this->mDevices.begin();
    while (    it != mDevices.end()
            || pDevices)
    {
        ComObjPtr<HostUSBDevice> pHostDevice;

        if (it != mDevices.end())
            pHostDevice = *it;

        /*
         * Assert that the object is still alive (we still reference it in
         * the collection and we're the only one who calls uninit() on it.
         */
        AutoCaller devCaller(pHostDevice.isNull() ? NULL : pHostDevice);
        AssertComRC(devCaller.rc());

        /*
         * Lock the device object since we will read/write its
         * properties. All Host callbacks also imply the object is locked.
         */
        AutoWriteLock devLock(pHostDevice.isNull() ? NULL : pHostDevice
                              COMMA_LOCKVAL_SRC_POS);

        /*
         * Compare.
         */
        int iDiff;
        if (pHostDevice.isNull())
            iDiff = 1;
        else
        {
            if (!pDevices)
                iDiff = -1;
            else
                iDiff = pHostDevice->compare(pDevices);
        }
        if (!iDiff)
        {
            /*
             * The device still there, update the state and move on. The PUSBDEVICE
             * structure is eaten by updateDeviceState / HostUSBDevice::updateState().
             */
            PUSBDEVICE pCur = pDevices;
            pDevices = pDevices->pNext;
            pCur->pPrev = pCur->pNext = NULL;

            bool fRunFilters = false;
            SessionMachine *pIgnoreMachine = NULL;
            devLock.release();
            alock.release();
            if (updateDeviceState(pHostDevice, pCur, &fRunFilters, &pIgnoreMachine))
                deviceChanged(pHostDevice,
                              (fRunFilters ? &llOpenedMachines : NULL),
                              pIgnoreMachine);
            alock.acquire();
            it++;
        }
        else
        {
            if (iDiff > 0)
            {
                /*
                 * Head of pDevices was attached.
                 */
                PUSBDEVICE pNew = pDevices;
                pDevices = pDevices->pNext;
                pNew->pPrev = pNew->pNext = NULL;

                ComObjPtr<HostUSBDevice> NewObj;
                NewObj.createObject();
                NewObj->init(pNew, this);
                Log(("USBProxyService::processChanges: attached %p {%s} %s / %p:{.idVendor=%#06x, .idProduct=%#06x, .pszProduct=\"%s\", .pszManufacturer=\"%s\"}\n",
                     (HostUSBDevice *)NewObj,
                     NewObj->getName().c_str(),
                     NewObj->getStateName(),
                     pNew,
                     pNew->idVendor,
                     pNew->idProduct,
                     pNew->pszProduct,
                     pNew->pszManufacturer));

                mDevices.insert(it, NewObj);

                devLock.release();
                alock.release();
                deviceAdded(NewObj, llOpenedMachines, pNew);
                alock.acquire();
            }
            else
            {
                /*
                 * Check if the device was actually detached or logically detached
                 * as the result of a re-enumeration.
                 */
                if (!pHostDevice->wasActuallyDetached())
                    it++;
                else
                {
                    it = mDevices.erase(it);
                    devLock.release();
                    alock.release();
                    deviceRemoved(pHostDevice);
                    Log(("USBProxyService::processChanges: detached %p {%s}\n",
                         (HostUSBDevice *)pHostDevice,
                         pHostDevice->getName().c_str()));

                    /* from now on, the object is no more valid,
                     * uninitialize to avoid abuse */
                    devCaller.release();
                    pHostDevice->uninit();
                    alock.acquire();
                }
            }
        }
    } /* while */

    LogFlowThisFunc(("returns void\n"));
}
Example #30
0
const QHash<QString, QString> WASAPISystem::getOutputDevices() {
	return getDevices(eRender);
}