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>()); }
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"); }
void updateValues( BorderSubdType i_BorderSubdType, const DeviceVector< T >& i_Src, const subd::TopologyData& i_Topo, int i_Stride, int i_Offset, DeviceVector< T >& o_Dst ) { assert( o_Dst.size() != 0 ); grind::subd::genFacePointsDevice( i_Topo.faceList.size(), i_Topo.faceList.getDevicePtr(), i_Src.getDevicePtr(), i_Topo.facePointsOffset, i_Topo.vertPointsOffset, i_Stride, i_Offset, o_Dst.getDevicePtr() ); grind::subd::tweakVertPointsDevice( i_Topo.srcVertCount, i_Topo.vertFaceValence.getDevicePtr(), i_Topo.vertEdgeValence.getDevicePtr(), i_Topo.vertPointsOffset, i_Stride, i_Offset, o_Dst.getDevicePtr() ); grind::subd::genEdgePointsDevice( i_Topo.edgeList.size(), i_Topo.edgeList.getDevicePtr(), i_Src.getDevicePtr(), i_Topo.vertFaceValence.getDevicePtr(), i_Topo.vertEdgeValence.getDevicePtr(), i_Topo.edgePointsOffset, i_Topo.vertPointsOffset, i_Stride, i_Offset, o_Dst.getDevicePtr() ); grind::subd::genVertPointsDevice( i_BorderSubdType, i_Topo.srcVertCount, i_Src.getDevicePtr(), i_Topo.vertFaceValence.getDevicePtr(), i_Topo.vertEdgeValence.getDevicePtr(), i_Topo.vertPointsOffset, i_Stride, i_Offset, o_Dst.getDevicePtr() ); }
DeviceVector DeviceVector::getDevicesFromTypeAddr( audio_devices_t type, const String8& address) const { DeviceVector devices; for (size_t i = 0; i < size(); i++) { if (itemAt(i)->type() == type) { if (itemAt(i)->mAddress == address) { devices.add(itemAt(i)); } } } return devices; }
void removeDevice(Freenect2DeviceImpl *device) { DeviceVector::iterator it = std::find(devices_.begin(), devices_.end(), device); if(it != devices_.end()) { devices_.erase(it); } else { std::cout << "[Freenect2Impl] tried to remove device, which is not in the internal device list!" << std::endl; } }
bool tryGetDevice(libusb_device *usb_device, Freenect2DeviceImpl **device) { for(DeviceVector::iterator it = devices_.begin(); it != devices_.end(); ++it) { if((*it)->isSameUsbDevice(usb_device)) { *device = *it; return true; } } return false; }
DeviceVector* transferVector(const Stream& stream, const PinnedHostVector& vectorHost) { const cudaStream_t& cudaStream = stream.getCudaStream(); const int numberOfRows = vectorHost.getNumberOfRows(); DeviceVector* deviceVector = new DeviceVector(numberOfRows); PRECISION* deviceVectorPointer = deviceVector->getMemoryPointer(); const PRECISION* hostVectorPointer = vectorHost.getMemoryPointer(); handleCublasStatus( cublasSetVectorAsync(numberOfRows, sizeof(PRECISION), hostVectorPointer, 1, deviceVectorPointer, 1, cudaStream), "Error when transferring vector from host to device: "); return deviceVector; }
void clearValues( const DeviceVector< T >& i_Src, const subd::TopologyData& i_Topo, int i_Stride, int i_Offset, DeviceVector< T >& o_Dst ) { size_t vert_count = i_Topo.faceList.size() + i_Topo.edgeList.size() + i_Topo.srcVertCount; if( i_Src.size() != i_Topo.srcVertCount * i_Stride ){ throw std::runtime_error( "mesh topology doesn't appear to match guide topology" ); } //! should provide a zero value for vec3, vec2, float etc const static T zero = T() * 0.0f; o_Dst.resize( vert_count * i_Stride ); setAllElements( zero, o_Dst ); }
void clearDevices() { DeviceVector devices(devices_.begin(), devices_.end()); for(DeviceVector::iterator it = devices.begin(); it != devices.end(); ++it) { delete (*it); } if(!devices_.empty()) { std::cout << "[Freenect2Impl] after deleting all devices the internal device list should be empty!" << std::endl; } }
size_t ConvNet::max_iter(DeviceVector<float> v) { size_t i = 0; //#ifdef NOTUNIFIEDMEMORY v.pop(); //#endif float_t max = v[0]; for (size_t j = 1; j < v.size(); j++) { if (v[j] > max) { max = v[j]; i = j; } } return i; }
DeviceVector ATIGPUDevice::createDevices(unsigned int flags) { DeviceVector devices; if(deviceCount() == 0) return devices; try { // Multiple devices is not supported yet devices.push_back(new ATIGPUDevice()); } catch (hydrazine::Exception he) { // Swallow the exception and return empty device vector report(he.what()); } return devices; }
void DeviceVector::loadDevicesFromTag(char *tag, const DeviceVector& declaredDevices) { char *devTag = strtok(tag, "|"); while (devTag != NULL) { if (strlen(devTag) != 0) { audio_devices_t type = ConfigParsingUtils::stringToEnum(sDeviceTypeToEnumTable, ARRAY_SIZE(sDeviceTypeToEnumTable), devTag); if (type != AUDIO_DEVICE_NONE) { sp<DeviceDescriptor> dev = new DeviceDescriptor(type); if (type == AUDIO_DEVICE_IN_REMOTE_SUBMIX || type == AUDIO_DEVICE_OUT_REMOTE_SUBMIX ) { dev->mAddress = String8("0"); } add(dev); } else { sp<DeviceDescriptor> deviceDesc = declaredDevices.getDeviceFromTag(String8(devTag)); if (deviceDesc != 0) { add(deviceDesc); } } } devTag = strtok(NULL, "|"); } }
DeviceVector DeviceVector::getDevicesFromType(audio_devices_t type) const { DeviceVector devices; bool isOutput = audio_is_output_devices(type); type &= ~AUDIO_DEVICE_BIT_IN; for (size_t i = 0; (i < size()) && (type != AUDIO_DEVICE_NONE); i++) { bool curIsOutput = audio_is_output_devices(itemAt(i)->mDeviceType); audio_devices_t curType = itemAt(i)->mDeviceType & ~AUDIO_DEVICE_BIT_IN; if ((isOutput == curIsOutput) && ((type & curType) != 0)) { devices.add(itemAt(i)); type &= ~curType; ALOGV("DeviceVector::getDevicesFromType() for type %x found %p", itemAt(i)->type(), itemAt(i).get()); } } return devices; }
//------------------------------------------------------------------------------------------------- void updateTopology( size_t i_SrcVertCount, const DeviceVector<int>& i_MeshConnectivity, const DeviceVector<int>& i_PolyVertCounts, subd::TopologyData& o_Topo, DeviceVector<int>* o_Id ) { o_Topo.srcVertCount = i_SrcVertCount; meshSanityCheck( i_PolyVertCounts ); o_Topo.cumulativePolyVertCounts.resize( i_PolyVertCounts.size() ); inclusiveScan( i_PolyVertCounts, o_Topo.cumulativePolyVertCounts ); o_Topo.vertEdgeValence.resize( o_Topo.srcVertCount ); setAllElements( 0, o_Topo.vertEdgeValence ); o_Topo.vertFaceValence.resize( o_Topo.srcVertCount ); setAllElements( 0, o_Topo.vertFaceValence ); int face_count = i_PolyVertCounts.size(); o_Topo.faceList.resize( face_count ); buildFaceListDevice( face_count, i_MeshConnectivity.getDevicePtr(), o_Topo.cumulativePolyVertCounts.getDevicePtr(), o_Topo.faceList.getDevicePtr(), o_Topo.vertFaceValence.getDevicePtr() ); int non_unique_edge_count = reduce( i_PolyVertCounts ); DeviceVector< grind::subd::Edge > d_edges; d_edges.resize( non_unique_edge_count ); int actual_edge_count = buildEdgeListDevice( face_count, i_MeshConnectivity.getDevicePtr(), o_Topo.cumulativePolyVertCounts.getDevicePtr(), d_edges.getDevicePtr(), o_Topo.vertEdgeValence.getDevicePtr() ); o_Topo.edgeList.setValueDevice( d_edges.getDevicePtr(), actual_edge_count ); int subd_quad_count = non_unique_edge_count; DRD_LOG_INFO( L, "faces before subd: " << face_count ); DRD_LOG_INFO( L, "faces after subd: " << subd_quad_count ); o_Topo.facePointsOffset = 0; o_Topo.edgePointsOffset = o_Topo.faceList.size(); o_Topo.vertPointsOffset = o_Topo.faceList.size() + o_Topo.edgeList.size(); if( o_Id != NULL ){ o_Id->resize( subd_quad_count * 4, -1 ); buildSubdFaceTopologyDevice( o_Topo.edgeList.size(), o_Topo.edgeList.getDevicePtr(), i_MeshConnectivity.getDevicePtr(), o_Topo.cumulativePolyVertCounts.getDevicePtr(), o_Topo.facePointsOffset, o_Topo.edgePointsOffset, o_Topo.vertPointsOffset, o_Id->getDevicePtr() ); } }
//------------------------------------------------------------------------------------------------- //! extrapolate end verts void buildCatmullRomP( int i_CurveCount, int i_CvCount, const DeviceVector<Imath::V3f>& i_P, HostVector<Imath::V3f>& o_Result ) { HostVector<Imath::V3f> p; i_P.getValue(p); int src_cv_id = 0; for( int curve = 0; curve < i_CurveCount; ++curve ){ // extend tangent before curve o_Result.push_back( p[src_cv_id]*2 - p[src_cv_id+1] ); for( int cv = 0; cv < i_CvCount; ++cv, ++src_cv_id ){ // copy curve value o_Result.push_back( p[src_cv_id] ); } // extend tangent after curve o_Result.push_back( p[src_cv_id-1]*2 - p[src_cv_id-2] ); } }
void CustomKernel::Input(DeviceVector& fDVec) { kernel->PushTexture(fDVec.GetTexture()); }
void CustomKernel::Output(DeviceVector& fDVec) { kernel->frameBuffer.SetSize(fDVec.GetWidth(), fDVec.GetHeight()); kernel->frameBuffer.AttachTexture(fDVec.GetTexture()); }
void addDevice(Freenect2DeviceImpl *device) { devices_.push_back(device); }
ErrorPtr DaliDeviceContainer::handleMethod(VdcApiRequestPtr aRequest, const string &aMethod, ApiValuePtr aParams) { ErrorPtr respErr; if (aMethod=="x-p44-groupDevices") { // create a composite device out of existing single-channel ones ApiValuePtr components; long long collectionID = -1; DeviceVector groupedDevices; respErr = checkParam(aParams, "members", components); if (Error::isOK(respErr)) { if (components->isType(apivalue_object)) { components->resetKeyIteration(); string dimmerType; ApiValuePtr o; while (components->nextKeyValue(dimmerType, o)) { DsUid memberUID; memberUID.setAsBinary(o->binaryValue()); bool deviceFound = false; // search for this device for (DeviceVector::iterator pos = devices.begin(); pos!=devices.end(); ++pos) { // only non-grouped DALI devices can be grouped DaliDevicePtr dev = boost::dynamic_pointer_cast<DaliDevice>(*pos); if (dev && dev->getDsUid() == memberUID) { deviceFound = true; // found this device, create DB entry for it db.executef( "INSERT OR REPLACE INTO compositeDevices (dimmerUID, dimmerType, collectionID) VALUES ('%s','%s',%lld)", memberUID.getString().c_str(), dimmerType.c_str(), collectionID ); if (collectionID<0) { // use rowid of just inserted item as collectionID collectionID = db.last_insert_rowid(); // - update already inserted first record db.executef( "UPDATE compositeDevices SET collectionID=%lld WHERE ROWID=%lld", collectionID, collectionID ); } // remember groupedDevices.push_back(dev); // done break; } } if (!deviceFound) { respErr = ErrorPtr(new WebError(404, "some devices of the group could not be found")); break; } } if (Error::isOK(respErr) && groupedDevices.size()>0) { // all components inserted into DB // - remove grouped single devices for (DeviceVector::iterator pos = groupedDevices.begin(); pos!=groupedDevices.end(); ++pos) { (*pos)->hasVanished(false); // vanish, but keep settings } // - re-collect devices to find grouped composite now, but only in a second starting from main loop, not from here CompletedCB cb = boost::bind(&DaliDeviceContainer::groupCollected, this, aRequest); MainLoop::currentMainLoop().executeOnce(boost::bind(&DaliDeviceContainer::collectDevices, this, cb, false, false), 1*Second); } } } } else { respErr = inherited::handleMethod(aRequest, aMethod, aParams); } return respErr; }