diff options
author | Cedric Nugteren <web@cedricnugteren.nl> | 2017-04-01 13:36:24 +0200 |
---|---|---|
committer | Cedric Nugteren <web@cedricnugteren.nl> | 2017-04-01 13:36:24 +0200 |
commit | b84d2296b87ac212474af855d916b12adf96bdb7 (patch) | |
tree | 0f2e85e1e1acef1d22f046499dd0b8a30e5da4f9 /test/routines/levelx/xomatcopy.hpp | |
parent | a98c00a2671b8981579f3a73dca8fb3365a95e53 (diff) |
Separated host-device and device-host memory copies from execution of the CBLAS reference code; for fair timing and code de-duplication
Diffstat (limited to 'test/routines/levelx/xomatcopy.hpp')
-rw-r--r-- | test/routines/levelx/xomatcopy.hpp | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/test/routines/levelx/xomatcopy.hpp b/test/routines/levelx/xomatcopy.hpp index d1064d0c..d5973b4c 100644 --- a/test/routines/levelx/xomatcopy.hpp +++ b/test/routines/levelx/xomatcopy.hpp @@ -23,13 +23,7 @@ namespace clblast { // ================================================================================================= template <typename T> -StatusCode RunReference(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) { - - // Data transfer from OpenCL to std::vector - std::vector<T> a_mat_cpu(args.a_size, static_cast<T>(0)); - std::vector<T> b_mat_cpu(args.b_size, static_cast<T>(0)); - buffers.a_mat.Read(queue, args.a_size, a_mat_cpu); - buffers.b_mat.Read(queue, args.b_size, b_mat_cpu); +StatusCode RunReference(const Arguments<T> &args, BuffersHost<T> &buffers_host) { // Checking for invalid arguments const auto a_rotated = (args.layout == Layout::kRowMajor); @@ -40,8 +34,8 @@ StatusCode RunReference(const Arguments<T> &args, Buffers<T> &buffers, Queue &qu if ((args.m == 0) || (args.n == 0)) { return StatusCode::kInvalidDimension; } if ((args.a_ld < args.m && !a_rotated) || (args.a_ld < args.n && a_rotated)) { return StatusCode::kInvalidLeadDimA; } if ((args.b_ld < args.m && !b_rotated) || (args.b_ld < args.n && b_rotated)) { return StatusCode::kInvalidLeadDimB; } - if (buffers.a_mat.GetSize() < (a_base + args.a_offset) * sizeof(T)) { return StatusCode::kInsufficientMemoryA; } - if (buffers.b_mat.GetSize() < (b_base + args.b_offset) * sizeof(T)) { return StatusCode::kInsufficientMemoryB; } + if (buffers_host.a_mat.size() * sizeof(T) < (a_base + args.a_offset) * sizeof(T)) { return StatusCode::kInsufficientMemoryA; } + if (buffers_host.b_mat.size() * sizeof(T) < (b_base + args.b_offset) * sizeof(T)) { return StatusCode::kInsufficientMemoryB; } // Matrix copy, scaling, and/or transpose for (auto id1 = size_t{0}; id1 < args.m; ++id1) { @@ -52,30 +46,27 @@ StatusCode RunReference(const Arguments<T> &args, Buffers<T> &buffers, Queue &qu const auto b_two = (b_rotated) ? id1 : id2; const auto a_index = a_two * args.a_ld + a_one + args.a_offset; const auto b_index = b_two * args.b_ld + b_one + args.b_offset; - b_mat_cpu[b_index] = args.alpha * a_mat_cpu[a_index]; + buffers_host.b_mat[b_index] = args.alpha * buffers_host.a_mat[a_index]; } } - - // Data transfer back to OpenCL - buffers.b_mat.Write(queue, args.b_size, b_mat_cpu); return StatusCode::kSuccess; } // Half-precision version calling the above reference implementation after conversions template <> -StatusCode RunReference<half>(const Arguments<half> &args, Buffers<half> &buffers, Queue &queue) { - auto a_buffer2 = HalfToFloatBuffer(buffers.a_mat, queue()); - auto b_buffer2 = HalfToFloatBuffer(buffers.b_mat, queue()); - auto dummy = clblast::Buffer<float>(0); - auto buffers2 = Buffers<float>{dummy, dummy, a_buffer2, b_buffer2, dummy, dummy, dummy}; +StatusCode RunReference<half>(const Arguments<half> &args, BuffersHost<half> &buffers_host) { + auto a_buffer2 = HalfToFloatBuffer(buffers_host.a_mat); + auto b_buffer2 = HalfToFloatBuffer(buffers_host.b_mat); + auto dummy = std::vector<float>(0); + auto buffers2 = BuffersHost<float>{dummy, dummy, a_buffer2, b_buffer2, dummy, dummy, dummy}; auto args2 = Arguments<float>(); args2.a_size = args.a_size; args2.b_size = args.b_size; args2.a_ld = args.a_ld; args2.b_ld = args.b_ld; args2.m = args.m; args2.n = args.n; args2.a_offset = args.a_offset; args2.b_offset = args.b_offset; args2.layout = args.layout; args2.a_transpose = args.a_transpose; args2.alpha = HalfToFloat(args.alpha); - auto status = RunReference(args2, buffers2, queue); - FloatToHalfBuffer(buffers.b_mat, b_buffer2, queue()); + auto status = RunReference(args2, buffers2); + FloatToHalfBuffer(buffers_host.b_mat, b_buffer2); return status; } @@ -97,6 +88,8 @@ class TestXomatcopy { kArgAOffset, kArgBOffset, kArgAlpha}; } + static std::vector<std::string> BuffersIn() { return {kBufMatA, kBufMatB}; } + static std::vector<std::string> BuffersOut() { return {kBufMatB}; } // Describes how to obtain the sizes of the buffers static size_t GetSizeA(const Arguments<T> &args) { @@ -148,11 +141,15 @@ class TestXomatcopy { // Describes how to run a naive version of the routine (for correctness/performance comparison). // Note that a proper clBLAS or CPU BLAS comparison is not available for non-BLAS routines. static StatusCode RunReference1(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) { - return RunReference(args, buffers, queue); + auto buffers_host = BuffersHost<T>(); + DeviceToHost(args, buffers, buffers_host, queue, BuffersIn()); + const auto status = RunReference(args, buffers_host); + HostToDevice(args, buffers, buffers_host, queue, BuffersOut()); + return status; } - static StatusCode RunReference2(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) { - return RunReference(args, buffers, queue); + static StatusCode RunReference2(const Arguments<T> &args, BuffersHost<T> &buffers_host, Queue&) { + return RunReference(args, buffers_host); } // Describes how to download the results of the computation (more importantly: which buffer) |