void* OCCA_RFUNC occaDeviceManagedMappedAlloc(occaDevice device, uintptr_t bytes, void *src) { occa::device device_((occa::device_v*) device); return device_.managedMappedAlloc(bytes, src); }
occaStream OCCA_RFUNC occaDeviceWrapStream(occaDevice device, void *handle_) { occa::device device_((occa::device_v*) device); occa::stream &newStream = *(new occa::stream(device_.wrapStream(handle_))); return (occaStream) &newStream; }
occaStream OCCA_RFUNC occaDeviceGetStream(occaDevice device) { occa::device device_((occa::device_v*) device); occa::stream ¤tStream = *(new occa::stream(device_.getStream())); return (occaStream) ¤tStream; }
occaStream OCCA_RFUNC occaDeviceCreateStream(occaDevice device) { occa::device device_((occa::device_v*) device); occa::stream &newStream = *(new occa::stream(device_.createStream())); return (occaStream) &newStream; }
void OCCA_RFUNC occaDeviceWaitFor(occaDevice device, occaStreamTag tag) { occa::device device_((occa::device_v*) device); occa::streamTag tag_; ::memcpy(&tag_, &tag, sizeof(tag_)); device_.waitFor(tag_); }
occaKernel OCCA_RFUNC occaDeviceBuildKernelFromBinary(occaDevice device, const char *filename, const char *functionName) { occa::device device_((occa::device_v*) device); occa::kernel kernel; kernel = device_.buildKernelFromBinary(filename, functionName); return (occaKernel) kernel.getKHandle(); }
occaStreamTag OCCA_RFUNC occaDeviceTagStream(occaDevice device) { occa::device device_((occa::device_v*) device); occa::streamTag oldTag = device_.tagStream(); occaStreamTag newTag; ::memcpy(&newTag, &oldTag, sizeof(oldTag)); return newTag; }
double OCCA_RFUNC occaDeviceTimeBetweenTags(occaDevice device, occaStreamTag startTag, occaStreamTag endTag) { occa::device device_((occa::device_v*) device); occa::streamTag startTag_, endTag_; ::memcpy(&startTag_, &startTag, sizeof(startTag_)); ::memcpy(&endTag_ , &endTag , sizeof(endTag_)); return device_.timeBetween(startTag_, endTag_); }
occaMemory OCCA_RFUNC occaDeviceMappedAlloc(occaDevice device, uintptr_t bytes, void *src) { occa::device device_((occa::device_v*) device); occa::memory memory_ = device_.mappedAlloc(bytes, src); occaMemory memory = occa::_newType(OCCA_TYPE_MEMORY); memory->ptr->value.data.void_ = memory_.getMHandle(); return memory; }
occaMemory OCCA_RFUNC occaDeviceWrapMemory(occaDevice device, void *handle_, const uintptr_t bytes) { occa::device device_((occa::device_v*) device); occa::memory memory_ = device_.wrapMemory(handle_, bytes); occaMemory memory = occa::_newType(OCCA_TYPE_MEMORY); memory->ptr->value.data.void_ = memory_.getMHandle(); return memory; }
occaMemory OCCA_RFUNC occaDeviceWrapMemory(occaDevice device, void *handle_, const uintptr_t bytes) { occa::device device_((occa::device_v*) device); occa::memory memory_ = device_.wrapMemory(handle_, bytes); occaMemory memory = (occaMemory) new occaTypePtr_t(); memory->type() = OCCA_TYPE_MEMORY; memory->value().data.void_ = memory_.getMHandle(); return memory; }
occaMemory OCCA_RFUNC occaDeviceMappedAlloc(occaDevice device, uintptr_t bytes, void *src) { occa::device device_((occa::device_v*) device); occa::memory memory_ = device_.mappedAlloc(bytes, src); occaMemory memory = (occaMemory) new occaTypePtr_t(); memory->type() = OCCA_TYPE_MEMORY; memory->value().data.void_ = memory_.getMHandle(); return memory; }
occaKernel OCCA_RFUNC occaDeviceBuildKernelFromSource(occaDevice device, const char *filename, const char *functionName, occaKernelInfo info) { occa::device device_((occa::device_v*) device); occa::kernel kernel; if(info != occaNoKernelInfo) { occa::kernelInfo &info_ = *((occa::kernelInfo*) info); kernel = device_.buildKernelFromSource(filename, functionName, info_); } else{ kernel = device_.buildKernelFromSource(filename, functionName); } return (occaKernel) kernel.getKHandle(); }
occaKernel OCCA_RFUNC occaDeviceBuildKernelFromString(occaDevice device, const char *str, const char *functionName, occaKernelInfo info, const int language) { occa::device device_((occa::device_v*) device); occa::kernel kernel; if(info != occaNoKernelInfo) { occa::kernelInfo &info_ = *((occa::kernelInfo*) info); kernel = device_.buildKernelFromString(str, functionName, info_, language); } else{ kernel = device_.buildKernelFromString(str, functionName, language); } return (occaKernel) kernel.getKHandle(); }
void Routine::InitProgram(std::initializer_list<const char *> source) { // Determines the identifier for this particular routine call auto routine_info = routine_name_; for (const auto &kernel_name : kernel_names_) { routine_info += "_" + kernel_name + db_(kernel_name).GetValuesString(); } log_debug(routine_info); // Queries the cache to see whether or not the program (context-specific) is already there bool has_program; program_ = ProgramCache::Instance().Get(ProgramKeyRef{ context_(), device_(), precision_, routine_info }, &has_program); if (has_program) { return; } // Sets the build options from an environmental variable (if set) auto options = std::vector<std::string>(); const auto environment_variable = std::getenv("CLBLAST_BUILD_OPTIONS"); if (environment_variable != nullptr) { options.push_back(std::string(environment_variable)); } // Queries the cache to see whether or not the binary (device-specific) is already there. If it // is, a program is created and stored in the cache const auto device_name = GetDeviceName(device_); const auto platform_id = device_.PlatformID(); bool has_binary; auto binary = BinaryCache::Instance().Get(BinaryKeyRef{platform_id, precision_, routine_info, device_name }, &has_binary); if (has_binary) { program_ = std::make_shared<Program>(device_, context_, binary); program_->Build(device_, options); ProgramCache::Instance().Store(ProgramKey{ context_(), device_(), precision_, routine_info }, std::shared_ptr<Program>{program_}); return; } // Otherwise, the kernel will be compiled and program will be built. Both the binary and the // program will be added to the cache. // Inspects whether or not FP64 is supported in case of double precision if ((precision_ == Precision::kDouble && !PrecisionSupported<double>(device_)) || (precision_ == Precision::kComplexDouble && !PrecisionSupported<double2>(device_))) { throw RuntimeErrorCode(StatusCode::kNoDoublePrecision); } // As above, but for FP16 (half precision) if (precision_ == Precision::kHalf && !PrecisionSupported<half>(device_)) { throw RuntimeErrorCode(StatusCode::kNoHalfPrecision); } // Collects the parameters for this device in the form of defines auto source_string = std::string{""}; for (const auto &kernel_name : kernel_names_) { source_string += db_(kernel_name).GetDefines(); } // Adds routine-specific code to the constructed source string for (const char *s: source) { source_string += s; } // Completes the source and compiles the kernel program_ = CompileFromSource(source_string, precision_, routine_name_, device_, context_, options, 0); // Store the compiled binary and program in the cache BinaryCache::Instance().Store(BinaryKey{platform_id, precision_, routine_info, device_name}, program_->GetIR()); ProgramCache::Instance().Store(ProgramKey{context_(), device_(), precision_, routine_info}, std::shared_ptr<Program>{program_}); }
//---[ Background Device ]------------ // |---[ Device ]-------------------- void OCCA_RFUNC occaSetDevice(occaDevice device) { occa::device device_((occa::device_v*) device); occa::setDevice(device_); }
void OCCA_RFUNC occaDeviceFree(occaDevice device) { occa::device device_((occa::device_v*) device); device_.free(); }
const char* OCCA_RFUNC occaDeviceMode(occaDevice device) { occa::device device_((occa::device_v*) device); return device_.mode().c_str(); }
void OCCA_RFUNC occaDeviceSetCompilerEnvScript(occaDevice device, const char *compilerEnvScript_) { occa::device device_((occa::device_v*) device); device_.setCompilerEnvScript(compilerEnvScript_); }
void OCCA_RFUNC occaDeviceSetCompilerFlags(occaDevice device, const char *compilerFlags) { occa::device device_((occa::device_v*) device); device_.setCompilerFlags(compilerFlags); }
void OCCA_RFUNC occaDeviceSetStream(occaDevice device, occaStream stream) { occa::device device_((occa::device_v*) device); device_.setStream(*((occa::stream*) stream)); }
void OCCA_RFUNC occaDeviceFinish(occaDevice device) { occa::device device_((occa::device_v*) device); device_.finish(); }
const char* OCCA_RFUNC occaDeviceGetCompilerFlags(occaDevice device) { occa::device device_((occa::device_v*) device); return device_.getCompilerEnvScript().c_str(); }
uintptr_t OCCA_RFUNC occaDeviceMemorySize(occaDevice device) { occa::device device_((occa::device_v*) device); return device_.memorySize(); }
// Old version of [occaDeviceMemoryAllocated()] uintptr_t OCCA_RFUNC occaDeviceBytesAllocated(occaDevice device) { occa::device device_((occa::device_v*) device); return device_.memoryAllocated(); }