Example #1
0
CLWProgram CLWProgram::CreateFromSource(char const* sourcecode, size_t sourcesize, CLWContext context)
{
    cl_int status = CL_SUCCESS;
    
    cl_program program = clCreateProgramWithSource(context, 1, (const char**)&sourcecode, &sourcesize, &status);
    
    ThrowIf(status != CL_SUCCESS, status, "clCreateProgramWithSource failed");
    
    std::vector<cl_device_id> deviceIds(context.GetDeviceCount());
    for(unsigned int i = 0; i < context.GetDeviceCount(); ++i)
    {
        deviceIds[i] = context.GetDevice(i);
    }

    char const* buildopts = 
#if defined(__APPLE__)
        "-D APPLE -cl-mad-enable -cl-fast-relaxed-math -cl-std=CL1.2 -I ."
#elif defined(_WIN32) || defined (WIN32)
        "-D WIN32 -cl-mad-enable -cl-std=CL1.2 -I."
#elif defined(__linux__)
        "-D __linux__ -I."
#else
        nullptr
#endif
        ;

    status = clBuildProgram(program, context.GetDeviceCount(), &deviceIds[0], buildopts, nullptr, nullptr);

    if(status != CL_SUCCESS)
    {
        std::vector<char> buildLog;
        size_t logSize;
        clGetProgramBuildInfo(program, deviceIds[0], CL_PROGRAM_BUILD_LOG, 0, nullptr, &logSize);

        buildLog.resize(logSize);
        clGetProgramBuildInfo(program, deviceIds[0], CL_PROGRAM_BUILD_LOG, logSize, &buildLog[0], nullptr);
        
#ifdef _DEBUG
        std::cout << &buildLog[0] << "\n";
#endif
        
        throw CLWException(status, std::string(&buildLog[0]));
    }
    
    CLWProgram prg(program);
    
    clReleaseProgram(program);

    return prg;
}
Example #2
0
/*! Returns the database query string for this \l{LogFilter}.*/
QString LogFilter::queryString() const
{
    if (isEmpty()) {
        return QString();
    }

    QString query;
    query.append(createDateString());

    if (!query.isEmpty() && !loggingSources().isEmpty()) {
        query.append("AND ");
    }
    query.append(createSourcesString());

    if (!query.isEmpty() && !loggingLevels().isEmpty()) {
        query.append("AND ");
    }
    query.append(createLevelsString());

    if (!query.isEmpty() && !loggingEventTypes().isEmpty()) {
        query.append("AND ");
    }
    query.append(createEventTypesString());

    if (!query.isEmpty() && !typeIds().isEmpty()) {
        query.append("AND ");
    }
    query.append(createTypeIdsString());

    if (!query.isEmpty() && !deviceIds().isEmpty()) {
        query.append("AND ");
    }
    query.append(createDeviceIdString());

    if (!query.isEmpty() && !values().isEmpty()) {
        query.append("AND ");
    }
    query.append(createValuesString());

    return query;
}
Example #3
0
CLWProgram CLWProgram::CreateFromSource(char const* sourcecode, size_t sourcesize, char const* buildopts, CLWContext context)
{
    cl_int status = CL_SUCCESS;
    
    cl_program program = clCreateProgramWithSource(context, 1, (const char**)&sourcecode, &sourcesize, &status);
    
    ThrowIf(status != CL_SUCCESS, status, "clCreateProgramWithSource failed");
    
    std::vector<cl_device_id> deviceIds(context.GetDeviceCount());
    for(unsigned int i = 0; i < context.GetDeviceCount(); ++i)
    {
        deviceIds[i] = context.GetDevice(i);
    }



    status = clBuildProgram(program, context.GetDeviceCount(), &deviceIds[0], buildopts, nullptr, nullptr);

    if(status != CL_SUCCESS)
    {
        std::vector<char> buildLog;
        size_t logSize;
        clGetProgramBuildInfo(program, deviceIds[0], CL_PROGRAM_BUILD_LOG, 0, nullptr, &logSize);

        buildLog.resize(logSize);
        clGetProgramBuildInfo(program, deviceIds[0], CL_PROGRAM_BUILD_LOG, logSize, &buildLog[0], nullptr);
        
#ifdef _DEBUG
        std::cout << &buildLog[0] << "\n";
#endif
        
        throw CLWException(status, std::string(&buildLog[0]));
    }
    
    CLWProgram prg(program);
    
    clReleaseProgram(program);

    return prg;
}
void OCLManagerMultiPlatform::configurePlatform(cl_platform_id platformId,
                                                base::OCLOperationConfiguration &configuration,
                                                bool useConfiguration) {
  cl_int err;

  char platformName[128] = {0};
  err = clGetPlatformInfo(platformId, CL_PLATFORM_NAME, 128 * sizeof(char), platformName, nullptr);

  if (CL_SUCCESS != err) {
    std::stringstream errorString;
    errorString << "OCL Error: can't get platform name!" << std::endl;
    throw SGPP::base::operation_exception(errorString.str());
  } else {
    if (verbose) {
      std::cout << "OCL Info: detected platform, name: \"" << platformName << "\"" << std::endl;
    }
  }

  if (verbose) {
    char vendor_name[128] = {0};
    err =
        clGetPlatformInfo(platformId, CL_PLATFORM_VENDOR, 128 * sizeof(char), vendor_name, nullptr);

    if (CL_SUCCESS != err) {
      std::stringstream errorString;
      errorString << "OCL Error: Can't get platform vendor!" << std::endl;
      throw SGPP::base::operation_exception(errorString.str());
    } else {
      std::cout << "OCL Info: detected platform vendor name: \"" << vendor_name << "\""
                << std::endl;
    }
  }

  if (useConfiguration) {
    if (!(*parameters)["PLATFORMS"].contains(platformName)) {
      return;
    }
  } else {
    // creating new configuration
    json::Node &platformNode = (*parameters)["PLATFORMS"].addDictAttr(platformName);
    platformNode.addDictAttr("DEVICES");
  }

  if (verbose) {
    std::cout << "OCL Info: using platform, name: \"" << platformName << "\"" << std::endl;
  }

  json::Node &devicesNode = (*parameters)["PLATFORMS"][platformName]["DEVICES"];

  uint32_t currentPlatformDevices;
  // get the number of devices
  err = clGetDeviceIDs(platformId, CL_DEVICE_TYPE_ALL, 0, nullptr, &currentPlatformDevices);

  if (err != CL_SUCCESS) {
    std::stringstream errorString;
    errorString << "OCL Error: Unable to get device count. Error Code: " << err << std::endl;
    throw SGPP::base::operation_exception(errorString.str());
  }

  std::vector<cl_device_id> deviceIds(currentPlatformDevices);
  err = clGetDeviceIDs(platformId, CL_DEVICE_TYPE_ALL, (cl_uint)currentPlatformDevices,
                       deviceIds.data(), nullptr);

  if (err != CL_SUCCESS) {
    std::stringstream errorString;
    errorString << "OCL Error: Unable to get device id for platform \"" << platformName
                << "\". Error Code: " << err << std::endl;
    throw SGPP::base::operation_exception(errorString.str());
  }

  std::vector<cl_device_id> filteredDeviceIds;

  std::vector<std::string> filteredDeviceNames;

  std::map<std::string, size_t> countLimitMap;

  for (cl_device_id deviceId : deviceIds) {
    // filter device ids
    this->configureDevice(deviceId, devicesNode, filteredDeviceIds, filteredDeviceNames,
                          countLimitMap, useConfiguration);
  }

  if (filteredDeviceIds.size() > 0) {
    OCLPlatformWrapper platformWrapper(platformId, platformName, filteredDeviceIds,
                                       filteredDeviceNames);
    //        platforms.emplace_back(platformId, platformName,
    //        filteredDeviceIds, filteredDeviceNames);
    //        OCLPlatformWrapper &platformWrapper = *(platforms.end() - 1);
    platforms.push_back(platformWrapper);

    // create linear device list
    for (size_t deviceIndex = 0; deviceIndex < filteredDeviceIds.size(); deviceIndex++) {
      this->devices.push_back(std::make_shared<OCLDevice>(
          platformWrapper.platformId, platformWrapper.deviceIds[deviceIndex], platformName,
          platformWrapper.deviceNames[deviceIndex], platformWrapper.context,
          platformWrapper.commandQueues[deviceIndex]));
    }
  }
}