Skip to content

Commit 2a36089

Browse files
Eric Ehlersjenkins
authored andcommitted
QPR-12535 avoid errors from GPU
1 parent 64d7570 commit 2a36089

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

QuantExt/qle/math/openclenvironment.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
#include <chrono>
3131
#include <iostream>
32-
#include <thread>
3332
#include <optional>
33+
#include <thread>
3434

3535
#define ORE_OPENCL_MAX_N_DEV_INFO 1024U
3636
#define ORE_OPENCL_MAX_N_DEV_INFO_LARGE 65536U
@@ -394,13 +394,13 @@ OpenClContext::~OpenClContext() {
394394
}
395395

396396
for (Size i = 0; i < kernel_.size(); ++i) {
397-
if (disposed_[i])
397+
if (disposed_[i] || !hasKernel_[i])
398398
continue;
399399
releaseKernel(kernel_[i], "ore kernel");
400400
}
401401

402402
for (Size i = 0; i < program_.size(); ++i) {
403-
if (disposed_[i])
403+
if (disposed_[i] || !hasKernel_[i])
404404
continue;
405405
releaseProgram(program_[i], "ore program");
406406
}
@@ -556,8 +556,10 @@ void OpenClContext::init() {
556556
void OpenClContext::disposeCalculation(const std::size_t id) {
557557
QL_REQUIRE(!disposed_[id - 1], "OpenClContext::disposeCalculation(): id " << id << " was already disposed.");
558558
disposed_[id - 1] = true;
559-
releaseKernel(kernel_[id - 1], "kernel id " + std::to_string(id) + " (during dispose())");
560-
releaseProgram(program_[id - 1], "program id " + std::to_string(id) + " (during dispose())");
559+
if (hasKernel_[id - 1]) {
560+
releaseKernel(kernel_[id - 1], "kernel id " + std::to_string(id) + " (during dispose())");
561+
releaseProgram(program_[id - 1], "program id " + std::to_string(id) + " (during dispose())");
562+
}
561563
}
562564

563565
std::pair<std::size_t, bool> OpenClContext::initiateCalculation(const std::size_t n, const std::size_t id,
@@ -691,6 +693,10 @@ void OpenClContext::updateVariatesPool() {
691693

692694
std::size_t fpSize = settings_.useDoublePrecision ? sizeof(double) : sizeof(float);
693695

696+
QL_REQUIRE(!settings_.useDoublePrecision || supportsDoublePrecision(),
697+
"OpenClContext::updateVariatesPool(): double precision is configured for this calculation, but not "
698+
"supported by the device. Switch to single precision or use an appropriate device.");
699+
694700
cl_event initEvent;
695701
if (variatesPoolSize_ == 0) {
696702

@@ -1279,7 +1285,6 @@ void OpenClContext::finalizeCalculation(std::vector<double*>& output) {
12791285
// build kernel if necessary
12801286

12811287
if (!hasKernel_[currentId_ - 1]) {
1282-
12831288
std::string fpTypeStr = settings_.useDoublePrecision ? "double" : "float";
12841289
std::string fpEpsStr = settings_.useDoublePrecision ? "0x1.0p-52" : "0x1.0p-23f";
12851290
std::string fpSuffix = settings_.useDoublePrecision ? std::string() : "f";
@@ -1466,7 +1471,6 @@ void OpenClContext::finalizeCalculation(std::vector<double*>& output) {
14661471
}
14671472

14681473
for (std::size_t part = 0; part < kernel_[currentId_ - 1].size(); ++part) {
1469-
14701474
bool initFromValues = part > 0;
14711475
bool cacheToValues = currentSsa_.size() > 1 && part < currentSsa_.size() - 1;
14721476
bool generateOutputValues = part == currentSsa_.size() - 1;

0 commit comments

Comments
 (0)