From 85341836dd4d24214f8eaa483d87a728568b41ca Mon Sep 17 00:00:00 2001 From: Cedric Nugteren Date: Thu, 17 May 2018 10:45:50 +0100 Subject: [PATCH] Added a canary region for overflow detection to the correctness tests --- CHANGELOG | 1 + test/correctness/testblas.cpp | 41 +++++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5f3ef371..22c23ee7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ Development (next version) - Added support for Intel specific subgroup shuffling extensions for faster GEMM on Intel GPUs - Re-added a local memory size constraint to the tuners - Updated and reorganised the CLBlast documentation +- Added a 'canary' region to check for overflows in the tuner and tests (insipred by clARMOR) - Fixed an access violation when compiled with Visual Studio upon releasing the OpenCL program - Various minor fixes and enhancements - Added tuned parameters for various devices (see doc/tuning.md) diff --git a/test/correctness/testblas.cpp b/test/correctness/testblas.cpp index aa4b4785..ddd29f80 100644 --- a/test/correctness/testblas.cpp +++ b/test/correctness/testblas.cpp @@ -66,14 +66,14 @@ TestBlas::TestBlas(const std::vector &arguments, const bool si const auto max_offset = *std::max_element(kOffsets.begin(), kOffsets.end()); const auto max_batch_count = *std::max_element(kBatchCounts.begin(), kBatchCounts.end()); - // Creates test input data - x_source_.resize(max_batch_count * std::max(max_vec, max_matvec)*max_inc + max_offset); - y_source_.resize(max_batch_count * std::max(max_vec, max_matvec)*max_inc + max_offset); - a_source_.resize(max_batch_count * std::max(max_mat, max_matvec)*std::max(max_ld, max_matvec) + max_offset); - b_source_.resize(max_batch_count * std::max(max_mat, max_matvec)*std::max(max_ld, max_matvec) + max_offset); - c_source_.resize(max_batch_count * std::max(max_mat, max_matvec)*std::max(max_ld, max_matvec) + max_offset); - ap_source_.resize(max_batch_count * std::max(max_mat, max_matvec)*std::max(max_mat, max_matvec) + max_offset); - scalar_source_.resize(max_batch_count * std::max(max_mat, max_matvec) + max_offset); + // Creates test input data. Adds a 'canary' region to detect buffer overflows + x_source_.resize(max_batch_count * std::max(max_vec, max_matvec)*max_inc + max_offset + kCanarySize); + y_source_.resize(max_batch_count * std::max(max_vec, max_matvec)*max_inc + max_offset + kCanarySize); + a_source_.resize(max_batch_count * std::max(max_mat, max_matvec)*std::max(max_ld, max_matvec) + max_offset + kCanarySize); + b_source_.resize(max_batch_count * std::max(max_mat, max_matvec)*std::max(max_ld, max_matvec) + max_offset + kCanarySize); + c_source_.resize(max_batch_count * std::max(max_mat, max_matvec)*std::max(max_ld, max_matvec) + max_offset + kCanarySize); + ap_source_.resize(max_batch_count * std::max(max_mat, max_matvec)*std::max(max_mat, max_matvec) + max_offset + kCanarySize); + scalar_source_.resize(max_batch_count * std::max(max_mat, max_matvec) + max_offset + kCanarySize); std::mt19937 mt(kSeed); std::uniform_real_distribution dist(kTestDataLowerLimit, kTestDataUpperLimit); PopulateVector(x_source_, mt, dist); @@ -94,7 +94,16 @@ void TestBlas::TestRegular(std::vector> &test_vector, const st TestStart("regular behaviour", name); // Iterates over all the to-be-tested combinations of arguments - for (const auto &args: test_vector) { + for (auto &args: test_vector) { + + // Adds a 'canary' region to detect buffer overflows + args.x_size += kCanarySize; + args.y_size += kCanarySize; + args.a_size += kCanarySize; + args.b_size += kCanarySize; + args.c_size += kCanarySize; + args.ap_size += kCanarySize; + args.scalar_size += kCanarySize; // Prints the current test configuration if (verbose_) { @@ -209,6 +218,20 @@ void TestBlas::TestRegular(std::vector> &test_vector, const st } } } + // Checks for differences in the 'canary' region to detect buffer overflows + for (auto canary_id=size_t{0}; canary_id 0) {