summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCedric Nugteren <web@cedricnugteren.nl>2016-05-01 14:03:37 +0200
committerCedric Nugteren <web@cedricnugteren.nl>2016-05-01 14:03:37 +0200
commitbee2f943ec51a3482e89cf635a2d12b6b6d96b04 (patch)
treefc93c1bef6fa19846959e55685129f439e6cfce9 /src
parent9602c150aa3b7f0a392207bef8cbb6048b1da891 (diff)
Changed the index buffer of IxAMAX routines to unsigned int for proper buffersize checking
Diffstat (limited to 'src')
-rw-r--r--src/clblast.cc6
-rw-r--r--src/routine.cc13
-rw-r--r--src/routines/level1/xamax.cc4
3 files changed, 18 insertions, 5 deletions
diff --git a/src/clblast.cc b/src/clblast.cc
index 4d7c9986..8a9465c3 100644
--- a/src/clblast.cc
+++ b/src/clblast.cc
@@ -475,7 +475,7 @@ StatusCode Amax(const size_t n,
auto status = routine.SetUp();
if (status != StatusCode::kSuccess) { return status; }
return routine.DoAmax(n,
- Buffer<T>(imax_buffer), imax_offset,
+ Buffer<unsigned int>(imax_buffer), imax_offset,
Buffer<T>(x_buffer), x_offset, x_inc);
}
template StatusCode PUBLIC_API Amax<float>(const size_t,
@@ -506,7 +506,7 @@ StatusCode Max(const size_t n,
auto status = routine.SetUp();
if (status != StatusCode::kSuccess) { return status; }
return routine.DoMax(n,
- Buffer<T>(imax_buffer), imax_offset,
+ Buffer<unsigned int>(imax_buffer), imax_offset,
Buffer<T>(x_buffer), x_offset, x_inc);
}
template StatusCode PUBLIC_API Max<float>(const size_t,
@@ -537,7 +537,7 @@ StatusCode Min(const size_t n,
auto status = routine.SetUp();
if (status != StatusCode::kSuccess) { return status; }
return routine.DoMin(n,
- Buffer<T>(imin_buffer), imin_offset,
+ Buffer<unsigned int>(imin_buffer), imin_offset,
Buffer<T>(x_buffer), x_offset, x_inc);
}
template StatusCode PUBLIC_API Min<float>(const size_t,
diff --git a/src/routine.cc b/src/routine.cc
index 35d0653c..8fa4cc79 100644
--- a/src/routine.cc
+++ b/src/routine.cc
@@ -267,6 +267,19 @@ StatusCode Routine<T>::TestVectorDot(const size_t n, const Buffer<T> &buffer, co
return StatusCode::kSuccess;
}
+// Tests vector index for validity: checks for a valid increment, a valid OpenCL buffer, and for a
+// sufficient buffer size.
+template <typename T>
+StatusCode Routine<T>::TestVectorIndex(const size_t n, const Buffer<unsigned int> &buffer,
+ const size_t offset, const size_t data_size) {
+ try {
+ auto required_size = (n + offset)*data_size;
+ auto buffer_size = buffer.GetSize();
+ if (buffer_size < required_size) { return StatusCode::kInsufficientMemoryDot; }
+ } catch (...) { return StatusCode::kInvalidVectorDot; }
+ return StatusCode::kSuccess;
+}
+
// =================================================================================================
// Copies or transposes a matrix and pads/unpads it with zeros
diff --git a/src/routines/level1/xamax.cc b/src/routines/level1/xamax.cc
index 33bd72a6..682e2b63 100644
--- a/src/routines/level1/xamax.cc
+++ b/src/routines/level1/xamax.cc
@@ -41,7 +41,7 @@ Xamax<T>::Xamax(Queue &queue, EventPointer event, const std::string &name):
// The main routine
template <typename T>
StatusCode Xamax<T>::DoAmax(const size_t n,
- const Buffer<T> &imax_buffer, const size_t imax_offset,
+ const Buffer<unsigned int> &imax_buffer, const size_t imax_offset,
const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc) {
// Makes sure all dimensions are larger than zero
@@ -50,7 +50,7 @@ StatusCode Xamax<T>::DoAmax(const size_t n,
// Tests the vectors for validity
auto status = TestVectorX(n, x_buffer, x_offset, x_inc, sizeof(T));
if (ErrorIn(status)) { return status; }
- status = TestVectorDot(1, imax_buffer, imax_offset, sizeof(T));
+ status = TestVectorIndex(1, imax_buffer, imax_offset, sizeof(unsigned int));
if (ErrorIn(status)) { return status; }
// Retrieves the Xamax kernels from the compiled binary