From b63a6179d8489fecd9956d8ff434fc27f4217195 Mon Sep 17 00:00:00 2001 From: PBerger Date: Thu, 13 Mar 2014 23:47:42 +0100 Subject: [PATCH] Fixed a possible bug in the equalModuloPrecision comparison of vectors. Same for the CUDA Kernel, but there all hell broke free. Former-commit-id: 6cb21c391962fda161a51bff543877ef701317f8 --- .../cudaForStorm/srcCuda/basicValueIteration.cu | 12 +++++++----- src/utility/vector.h | 5 ++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/resources/cudaForStorm/srcCuda/basicValueIteration.cu b/resources/cudaForStorm/srcCuda/basicValueIteration.cu index e42f36eda..25541adbc 100644 --- a/resources/cudaForStorm/srcCuda/basicValueIteration.cu +++ b/resources/cudaForStorm/srcCuda/basicValueIteration.cu @@ -14,7 +14,7 @@ #include #include - +#ifdef DEBUG #define CUDA_CHECK_ALL_ERRORS() do { \ cudaError_t errSync = cudaGetLastError(); \ cudaError_t errAsync = cudaDeviceSynchronize(); \ @@ -24,7 +24,9 @@ if (errAsync != cudaSuccess) { \ std::cout << "(DLL) Async kernel error: " << cudaGetErrorString(errAsync) << " (Code: " << errAsync << ")" << std::endl; \ } } while(false) - +#else +#define CUDA_CHECK_ALL_ERRORS() do {} while (false) +#endif template struct equalModuloPrecision : public thrust::binary_function @@ -32,6 +34,9 @@ struct equalModuloPrecision : public thrust::binary_function __host__ __device__ T operator()(const T &x, const T &y) const { if (Relative) { + if (y == 0) { + return x; + } const T result = (x - y) / y; return ((result >= 0) ? (result) : (-result)); } else { @@ -229,9 +234,6 @@ void basicValueIteration_mvReduce(uint_fast64_t const maxIterationCount, ValueTy converged = (maxX < precision); ++iterationCount; - // If there are empty rows in the matrix we need to clear multiplyResult - thrust::fill(devicePtrThrust_multiplyResult, devicePtrThrust_multiplyResult + matrixRowCount, 0); - // Swap pointers, device_x always contains the most current result std::swap(device_x, device_xSwap); } diff --git a/src/utility/vector.h b/src/utility/vector.h index dd3bb2a1f..6527d7b19 100644 --- a/src/utility/vector.h +++ b/src/utility/vector.h @@ -330,7 +330,10 @@ namespace storm { template bool equalModuloPrecision(T const& val1, T const& val2, T precision, bool relativeError = true) { if (relativeError) { - if (std::abs(val1 - val2)/val2 > precision) return false; + if (val2 == 0) { + return (val1 > precision); + } + if (std::abs((val1 - val2)/val2) > precision) return false; } else { if (std::abs(val1 - val2) > precision) return false; }