~DriversHelper() {
     for (unsigned int i=0; i<delegates.size(); i++) {
         if (delegates[i]==NULL) continue;
         delete delegates[i];
     }
     delegates.clear();
 }
示例#2
0
 bool add(const char *name, yarp::os::Searchable& config) {
     //printf("ADDING %s\n", config.toString().c_str());
     PolyDriver *pd = new PolyDriver();
     YARP_ASSERT (pd!=NULL);
     bool result = pd->open(config);
     if (!result) {
         delete pd;
         return false;
     }
     drivers.push_back(pd);
     names.push_back(ConstString(name));
     IService *service = NULL;
     pd->view(service);
     bool backgrounded = true;
     if (service!=NULL) {
         backgrounded = service->startService();
         if (backgrounded) {
             // we don't need to poll this, so forget about the
             // service interface
             printf("group: service backgrounded\n");
             service = NULL;
         }
     }
     needDrive.push_back(!backgrounded);
     needDriveSummary = needDriveSummary || (!backgrounded);
     Drivers::factory().add(new DriverLinkCreator(name,*pd));
     return true;
 }
示例#3
0
void OCLSample::initOpenCL() {
  cl_int result;

  // First, select an OpenCL platform
  typedef std::vector<cl::Platform> PlatformVector;
  PlatformVector platforms;
  result = cl::Platform::get(&platforms);
  assert(result == CL_SUCCESS && "Failed to retrieve OpenCL platform");
  assert(platforms.size() > 0 && "No OpenCL platforms found");

  // For now, just blindly select the first platform.
  // @TODO: Implement a check here for the NVidia OpenCL platform.
  platform_ = platforms[0];

  // Create an OpenCL context.
  cl_context_properties cps[] = { CL_CONTEXT_PLATFORM,
    (cl_context_properties)(platform_)(), 0 };
  context_ = cl::Context(CL_DEVICE_TYPE_GPU, cps, NULL, NULL, &result);
  assert(result == CL_SUCCESS && "Failed to create OpenCL context");

  // Retrieve the available OpenCL devices.
  typedef std::vector<cl::Device> DeviceVector;
  DeviceVector devices;
  devices = context_.getInfo<CL_CONTEXT_DEVICES>();
  assert(devices.size() > 0 && "No OpenCL devices found");

  // For now, just blindly select the first device.
  // @TODO: Implement some sort of device check here.
  device_ = devices[0];

  // Create a command queue
  queue_ = cl::CommandQueue(context_, device_, CL_QUEUE_PROFILING_ENABLE, &result);
  assert(result == CL_SUCCESS && "Failed to create command queue");
}
示例#4
0
CLContext::CLContext() {
  cl_int         result;
  PlatformVector allPlatforms;

  result = cl::Platform::get(&allPlatforms);
  throwOnError("cl::Platform::get", result);

  if(allPlatforms.size() == 0) {
    throw std::runtime_error("No platforms available");
  }

  platform_ = allPlatforms[0];

  //printValue("Platform", platform_.getInfo<CL_PLATFORM_NAME>());

  // Create context
  cl_context_properties cps[3] = {
    CL_CONTEXT_PLATFORM,
    (cl_context_properties)(platform_)(),
    0
  };

  context_ = cl::Context(CL_DEVICE_TYPE_GPU, cps, NULL, NULL, &result);
  throwOnError("cl::Context", result);

  DeviceVector allDevices = context_.getInfo<CL_CONTEXT_DEVICES>();

  if(allDevices.size() == 0) {
    throw std::runtime_error("No devices available");
  }

  device_ = allDevices[0];

  //printValue("Device", device_.getInfo<CL_DEVICE_NAME>());
}
 DriverCreator *find(const char *name) {
     for (unsigned int i=0; i<delegates.size(); i++) {
         if (delegates[i]==NULL) continue;
         ConstString s = delegates[i]->toString();
         if (s==name) {
             return delegates[i];
         }
     }
     return load(name);
 }
 bool remove(const char *name) {
     for (unsigned int i=0; i<delegates.size(); i++) {
         if (delegates[i]==NULL) continue;
         ConstString s = delegates[i]->toString();
         if (s==name) {
             delete delegates[i];
             delegates[i] = NULL;
         }
     }
     return false;
 }
示例#7
0
 void clear() {
     mutex.wait();
     PlatformVector<PolyDriver *>& lst = drivers;
     for (unsigned int i=0; i<lst.size(); i++) {
         printf("*** Removing %s\n",names[i].c_str());
         Drivers::factory().remove(names[i].c_str());
         //printf("*** removed %s\n",names[i].c_str());
         delete lst[i];
         //printf("*** deleted %s\n",names[i].c_str());
     }
     lst.clear();
     names.clear();
     mutex.post();
 }
    ConstString toString() {
        ConstString s;
        Property done;
        for (unsigned int i=0; i<delegates.size(); i++) {
            if (delegates[i]==NULL) continue;
            ConstString name = delegates[i]->getName();
            done.put(name,1);
            ConstString wrapper = delegates[i]->getWrapper();
            s += "Device \"";
            s += delegates[i]->getName();
            s += "\"";
            s += ",";
            s += " C++ class ";
            s += delegates[i]->getCode();
            s += ", ";
            if (wrapper=="") {
                s += "has no network wrapper";
            } else if (wrapper!=name) {
                s += "wrapped by \"";
                s += delegates[i]->getWrapper();
                s += "\"";
            } else {
                s += "is a network wrapper.";
            }
            s += "\n";
        }

        scan();
        Bottle lst = getSelectedPlugins();
        for (int i=0; i<lst.size(); i++) {
            Value& prop = lst.get(i);
            ConstString name = prop.check("name",Value("untitled")).asString();
            if (done.check(name)) continue;

            SharedLibraryFactory lib;
            YarpPluginSettings settings;
            settings.setSelector(*this);
            settings.readFromSearchable(prop,name);
            settings.open(lib);
            ConstString location = lib.getName().c_str();
            if (location=="") continue;

            ConstString cxx = prop.check("cxx",Value("unknown")).asString();
            ConstString wrapper = prop.check("wrapper",Value("unknown")).asString();
            s += "Device \"";
            s += name;
            s += "\"";
            s += ",";
            s += " available on request (found in ";
            s += location;
            s += " library)";
            if (cxx!="unknown") {
                s += ", C++ class ";
                s += cxx;
                s += "  ";
            }
            if (wrapper=="") {
                s += "no network wrapper known";
            } else if (wrapper=="unknown") {
                //s += "network wrapper unknown";
            } else if (wrapper!=name) {
                s += "wrapped by \"";
                s += delegates[i]->getWrapper();
                s += "\"";
            } else {
                s += "is a network wrapper.";
            }
            s += "\n";            
        }

        return s;
    }
 void add(DriverCreator *creator) {
     if (creator!=NULL) {
         delegates.push_back(creator);
     }
 }