Browse Source

Fixed a possible bug in the equalModuloPrecision comparison of vectors.

Same for the CUDA Kernel, but there all hell broke free.


Former-commit-id: 6cb21c3919
tempestpy_adaptions
PBerger 11 years ago
parent
commit
b63a6179d8
  1. 12
      resources/cudaForStorm/srcCuda/basicValueIteration.cu
  2. 5
      src/utility/vector.h

12
resources/cudaForStorm/srcCuda/basicValueIteration.cu

@ -14,7 +14,7 @@
#include <thrust/device_ptr.h>
#include <thrust/functional.h>
#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<typename T, bool Relative>
struct equalModuloPrecision : public thrust::binary_function<T,T,T>
@ -32,6 +34,9 @@ struct equalModuloPrecision : public thrust::binary_function<T,T,T>
__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);
}

5
src/utility/vector.h

@ -330,7 +330,10 @@ namespace storm {
template<class T>
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;
}

Loading…
Cancel
Save