summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Nugteren <web@cedricnugteren.nl>2017-07-16 22:33:49 +0200
committerCedric Nugteren <web@cedricnugteren.nl>2017-07-16 22:33:49 +0200
commit97bcf77d4bc9b31e32a8785787e0497ac5440e44 (patch)
treeceb0601fc0e2ea009ba46b44be314fdb02eb9e74
parent84ec50e29dc123b956a85e1dc37dae123323e420 (diff)
First step towards supporting im2col in the test infrastructure
-rw-r--r--src/utilities/utilities.hpp25
-rw-r--r--test/correctness/routines/levelx/xim2col.cpp26
-rw-r--r--test/correctness/testblas.hpp54
-rw-r--r--test/correctness/tester.cpp5
-rw-r--r--test/performance/routines/levelx/xim2col.cpp33
-rw-r--r--test/routines/levelx/xim2col.hpp165
-rw-r--r--test/routines/levelx/xomatcopy.hpp2
7 files changed, 306 insertions, 4 deletions
diff --git a/src/utilities/utilities.hpp b/src/utilities/utilities.hpp
index 03051354..8daeda08 100644
--- a/src/utilities/utilities.hpp
+++ b/src/utilities/utilities.hpp
@@ -78,6 +78,19 @@ constexpr auto kArgAlpha = "alpha";
constexpr auto kArgBeta = "beta";
constexpr auto kArgBatchCount = "batch_num";
+// Constants for im2col
+constexpr auto kArgChannels = "channels";
+constexpr auto kArgHeight = "height";
+constexpr auto kArgWidth = "width";
+constexpr auto kArgKernelH = "kernelh";
+constexpr auto kArgKernelW = "kernelw";
+constexpr auto kArgPadH = "padh";
+constexpr auto kArgPadW = "padw";
+constexpr auto kArgStrideH = "strideh";
+constexpr auto kArgStrideW = "stridew";
+constexpr auto kArgDilationH = "dilationh";
+constexpr auto kArgDilationW = "dilationw";
+
// The tuner-specific arguments in string form
constexpr auto kArgFraction = "fraction";
@@ -170,6 +183,18 @@ struct Arguments {
size_t imax_offset = 0;
T alpha = ConstantOne<T>();
T beta = ConstantOne<T>();
+ // Arguments for im2col
+ size_t channels = 1;
+ size_t height = 1;
+ size_t width = 1;
+ size_t kernel_h = 1;
+ size_t kernel_w = 1;
+ size_t pad_h = 1;
+ size_t pad_w = 1;
+ size_t stride_h = 1;
+ size_t stride_w = 1;
+ size_t dilation_h = 1;
+ size_t dilation_w = 1;
// Batch-specific arguments
size_t batch_count = 1;
std::vector<size_t> x_offsets; // = {0};
diff --git a/test/correctness/routines/levelx/xim2col.cpp b/test/correctness/routines/levelx/xim2col.cpp
new file mode 100644
index 00000000..fe79b3ef
--- /dev/null
+++ b/test/correctness/routines/levelx/xim2col.cpp
@@ -0,0 +1,26 @@
+
+// =================================================================================================
+// This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This
+// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max-
+// width of 100 characters per line.
+//
+// Author(s):
+// Cedric Nugteren <www.cedricnugteren.nl>
+//
+// =================================================================================================
+
+#include "test/correctness/testblas.hpp"
+#include "test/routines/levelx/xim2col.hpp"
+
+// Main function (not within the clblast namespace)
+int main(int argc, char *argv[]) {
+ auto errors = size_t{0};
+ errors += clblast::RunTests<clblast::TestXim2col<float>, float, float>(argc, argv, false, "SIM2COL");
+ errors += clblast::RunTests<clblast::TestXim2col<double>, double, double>(argc, argv, true, "DIM2COL");
+ errors += clblast::RunTests<clblast::TestXim2col<clblast::float2>, clblast::float2, clblast::float2>(argc, argv, true, "CIM2COL");
+ errors += clblast::RunTests<clblast::TestXim2col<clblast::double2>, clblast::double2, clblast::double2>(argc, argv, true, "ZIM2COL");
+ errors += clblast::RunTests<clblast::TestXim2col<clblast::half>, clblast::half, clblast::half>(argc, argv, true, "HIM2COL");
+ if (errors > 0) { return 1; } else { return 0; }
+}
+
+// =================================================================================================
diff --git a/test/correctness/testblas.hpp b/test/correctness/testblas.hpp
index a553687d..577a289e 100644
--- a/test/correctness/testblas.hpp
+++ b/test/correctness/testblas.hpp
@@ -56,6 +56,8 @@ class TestBlas: public Tester<T,U> {
static const std::vector<size_t> kMatrixDims;
static const std::vector<size_t> kMatrixVectorDims;
static const std::vector<size_t> kBandSizes;
+ static const std::vector<size_t> kPadSizes;
+ static const std::vector<size_t> kKernelSizes;
static const std::vector<size_t> kBatchCounts;
const std::vector<size_t> kOffsets;
const std::vector<U> kAlphaValues;
@@ -130,6 +132,8 @@ template <typename T, typename U> const std::vector<size_t> TestBlas<T,U>::kMatr
template <typename T, typename U> const std::vector<size_t> TestBlas<T,U>::kMatrixVectorDims = { 61, 256 };
template <typename T, typename U> const std::vector<size_t> TestBlas<T,U>::kBandSizes = { 4, 19 };
template <typename T, typename U> const std::vector<size_t> TestBlas<T,U>::kBatchCounts = { 1, 3 };
+template <typename T, typename U> const std::vector<size_t> TestBlas<T,U>::kPadSizes = { 0 };
+template <typename T, typename U> const std::vector<size_t> TestBlas<T,U>::kKernelSizes = { 1, 3 };
// Test settings for the invalid tests
template <typename T, typename U> const std::vector<size_t> TestBlas<T,U>::kInvalidIncrements = { 0, 1 };
@@ -223,6 +227,17 @@ size_t RunTests(int argc, char *argv[], const bool silent, const std::string &na
auto imax_offsets = std::vector<size_t>{args.imax_offset};
auto alphas = std::vector<U>{args.alpha};
auto betas = std::vector<U>{args.beta};
+ auto channelss = std::vector<size_t>{args.channels};
+ auto heights = std::vector<size_t>{args.height};
+ auto widths = std::vector<size_t>{args.width};
+ auto kernel_hs = std::vector<size_t>{args.kernel_h};
+ auto kernel_ws = std::vector<size_t>{args.kernel_w};
+ auto pad_hs = std::vector<size_t>{args.pad_h};
+ auto pad_ws = std::vector<size_t>{args.pad_w};
+ auto stride_hs = std::vector<size_t>{args.stride_h};
+ auto stride_ws = std::vector<size_t>{args.stride_w};
+ auto dilation_hs = std::vector<size_t>{args.dilation_h};
+ auto dilation_ws = std::vector<size_t>{args.dilation_w};
auto batch_counts = std::vector<size_t>{args.batch_count};
auto x_sizes = std::vector<size_t>{args.x_size};
auto y_sizes = std::vector<size_t>{args.y_size};
@@ -267,6 +282,17 @@ size_t RunTests(int argc, char *argv[], const bool silent, const std::string &na
if (option == kArgImaxOffset) { imax_offsets = tester.kOffsets; }
if (option == kArgAlpha) { alphas = tester.kAlphaValues; }
if (option == kArgBeta) { betas = tester.kBetaValues; }
+ if (option == kArgChannels) { channelss = tester.kMatrixDims; }
+ if (option == kArgHeight) { heights = tester.kMatrixDims; }
+ if (option == kArgWidth) { widths = tester.kMatrixDims; }
+ if (option == kArgKernelH) { kernel_hs = tester.kKernelSizes; }
+ if (option == kArgKernelW) { kernel_ws = tester.kKernelSizes; }
+ if (option == kArgPadH) { pad_hs = tester.kPadSizes; }
+ if (option == kArgPadW) { pad_ws = tester.kPadSizes; }
+ if (option == kArgStrideH) { stride_hs = tester.kKernelSizes; }
+ if (option == kArgStrideW) { stride_ws = tester.kKernelSizes; }
+ if (option == kArgDilationH) { dilation_hs = tester.kKernelSizes; }
+ if (option == kArgDilationW) { dilation_ws = tester.kKernelSizes; }
if (option == kArgBatchCount) { batch_counts = tester.kBatchCounts; }
if (option == kArgXOffset) { x_sizes = tester.kVecSizes; }
@@ -310,9 +336,31 @@ size_t RunTests(int argc, char *argv[], const bool silent, const std::string &na
for (auto &imax_offset: imax_offsets) { r_args.imax_offset = imax_offset;
for (auto &alpha: alphas) { r_args.alpha = alpha;
for (auto &beta: betas) { r_args.beta = beta;
- for (auto &batch_count: batch_counts) { r_args.batch_count = batch_count;
- C::SetSizes(r_args);
- regular_test_vector.push_back(r_args);
+ for (auto &channels: channelss) { r_args.channels = channels;
+ for (auto &height: heights) { r_args.height = height;
+ for (auto &width: widths) { r_args.width = width;
+ for (auto &kernel_h: kernel_hs) { r_args.kernel_h = kernel_h;
+ for (auto &kernel_w: kernel_ws) { r_args.kernel_w = kernel_w;
+ for (auto &pad_h: pad_hs) { r_args.pad_h = pad_h;
+ for (auto &pad_w: pad_ws) { r_args.pad_w = pad_w;
+ for (auto &stride_h: stride_hs) { r_args.stride_h = stride_h;
+ for (auto &stride_w: stride_ws) { r_args.stride_w = stride_w;
+ for (auto &dilation_h: dilation_hs) { r_args.dilation_h = dilation_h;
+ for (auto &dilation_w: dilation_ws) { r_args.dilation_w = dilation_w;
+ for (auto &batch_count: batch_counts) { r_args.batch_count = batch_count;
+ C::SetSizes(r_args);
+ regular_test_vector.push_back(r_args);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
}
}
diff --git a/test/correctness/tester.cpp b/test/correctness/tester.cpp
index fb85e609..1581fbfb 100644
--- a/test/correctness/tester.cpp
+++ b/test/correctness/tester.cpp
@@ -366,6 +366,11 @@ std::string Tester<T,U>::GetOptionsString(const Arguments<U> &args) {
if (o == kArgAlpha) { result += kArgAlpha + equals + ToString(args.alpha) + " "; }
if (o == kArgBeta) { result += kArgBeta + equals + ToString(args.beta) + " "; }
if (o == kArgBatchCount){result += kArgBatchCount + equals + ToString(args.batch_count) + " "; }
+ if (o == kArgChannels) { result += kArgChannels + equals + ToString(args.channels) + " "; }
+ if (o == kArgHeight) { result += kArgHeight + equals + ToString(args.height) + " "; }
+ if (o == kArgWidth) { result += kArgWidth + equals + ToString(args.width) + " "; }
+ if (o == kArgKernelH) { result += kArgKernelH + equals + ToString(args.kernel_h) + " "; }
+ if (o == kArgKernelW) { result += kArgKernelW + equals + ToString(args.kernel_w) + " "; }
}
return result;
}
diff --git a/test/performance/routines/levelx/xim2col.cpp b/test/performance/routines/levelx/xim2col.cpp
new file mode 100644
index 00000000..30e224f8
--- /dev/null
+++ b/test/performance/routines/levelx/xim2col.cpp
@@ -0,0 +1,33 @@
+
+// =================================================================================================
+// This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This
+// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max-
+// width of 100 characters per line.
+//
+// Author(s):
+// Cedric Nugteren <www.cedricnugteren.nl>
+//
+// =================================================================================================
+
+#include "test/performance/client.hpp"
+#include "test/routines/levelx/xim2col.hpp"
+
+// Main function (not within the clblast namespace)
+int main(int argc, char *argv[]) {
+ const auto command_line_args = clblast::RetrieveCommandLineArguments(argc, argv);
+ switch(clblast::GetPrecision(command_line_args, clblast::Precision::kSingle)) {
+ case clblast::Precision::kHalf:
+ clblast::RunClient<clblast::TestXim2col<clblast::half>, clblast::half, clblast::half>(argc, argv); break;
+ case clblast::Precision::kSingle:
+ clblast::RunClient<clblast::TestXim2col<float>, float, float>(argc, argv); break;
+ case clblast::Precision::kDouble:
+ clblast::RunClient<clblast::TestXim2col<double>, double, double>(argc, argv); break;
+ case clblast::Precision::kComplexSingle:
+ clblast::RunClient<clblast::TestXim2col<clblast::float2>, clblast::float2, clblast::float2>(argc, argv); break;
+ case clblast::Precision::kComplexDouble:
+ clblast::RunClient<clblast::TestXim2col<clblast::double2>, clblast::double2, clblast::double2>(argc, argv); break;
+ }
+ return 0;
+}
+
+// =================================================================================================
diff --git a/test/routines/levelx/xim2col.hpp b/test/routines/levelx/xim2col.hpp
new file mode 100644
index 00000000..e5bc56cd
--- /dev/null
+++ b/test/routines/levelx/xim2col.hpp
@@ -0,0 +1,165 @@
+
+// =================================================================================================
+// This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This
+// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max-
+// width of 100 characters per line.
+//
+// Author(s):
+// Cedric Nugteren <www.cedricnugteren.nl>
+//
+// This file implements a class with static methods to describe the Xim2col routine. Examples of
+// such 'descriptions' are how to calculate the size a of buffer or how to run the routine. These
+// static methods are used by the correctness tester and the performance tester.
+//
+// =================================================================================================
+
+#ifndef CLBLAST_TEST_ROUTINES_XIM2COL_H_
+#define CLBLAST_TEST_ROUTINES_XIM2COL_H_
+
+#include "test/routines/common.hpp"
+
+namespace clblast {
+// =================================================================================================
+
+template <typename T>
+StatusCode RunReference(const Arguments<T> &args, BuffersHost<T> &buffers_host) {
+ for (auto c_id = size_t{0}; c_id < args.channels; ++c_id) { // input channels
+ for (auto kh_id = size_t{0}; kh_id < args.kernel_h; ++kh_id) { // kernel height
+ for (auto kw_id = size_t{0}; kw_id < args.kernel_w; ++kw_id) { // kernel width
+ for (auto h_id = size_t{0}; h_id < args.height; h_id += args.stride_h) { // image height
+ for (auto w_id = size_t{0}; w_id < args.width; w_id += args.stride_w) { // image width
+
+ // Retrieves the input value
+ const auto h_index = -args.pad_h + kh_id * args.dilation_h + h_id;
+ const auto w_index = -args.pad_w + kw_id * args.dilation_w + w_id;
+ auto val = ConstantZero<T>();
+ if (h_index < args.height && w_index < args.width) {
+ const auto input_index = w_index + args.width * (h_index + args.height * c_id);
+ val = buffers_host.a_mat[input_index + args.a_offset];
+ }
+
+ // Sets the output value
+ const auto kernel_index = kw_id + args.kernel_w * kh_id;
+ const auto patch_index = w_id + ((args.width / args.stride_w) * h_id + (args.height / args.stride_h) * c_id);
+ const auto output_index = kernel_index + args.kernel_h * args.kernel_w * patch_index;
+ buffers_host.b_mat[output_index + args.b_offset] = val;
+ }
+ }
+ }
+ }
+ }
+ return StatusCode::kSuccess;
+}
+
+// =================================================================================================
+
+// See comment at top of file for a description of the class
+template <typename T>
+class TestXim2col {
+public:
+
+ // The BLAS level: 4 for the extra routines
+ static size_t BLASLevel() { return 4; }
+
+ // The list of arguments relevant for this routine
+ static std::vector<std::string> GetOptions() {
+ return {kArgChannels, kArgHeight, kArgWidth, kArgKernelH, kArgKernelW, kArgPadH, kArgPadW,
+ kArgStrideH, kArgStrideW, kArgDilationH, kArgDilationW,
+ kArgAOffset, kArgBOffset};
+ }
+ 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 NumPatches(const Arguments<T> &args) {
+ return (args.width / args.stride_w) * (args.height / args.stride_h) * args.channels;
+ }
+ static size_t GetSizeA(const Arguments<T> &args) {
+ return args.height * args.width * args.channels + args.a_offset;
+ }
+ static size_t GetSizeB(const Arguments<T> &args) {
+ return args.kernel_w * args.kernel_h * NumPatches(args) + args.b_offset;
+ }
+
+ // Describes how to set the sizes of all the buffers
+ static void SetSizes(Arguments<T> &args) {
+ args.a_size = GetSizeA(args);
+ args.b_size = GetSizeB(args);
+ }
+
+ // Describes what the default values of the leading dimensions of the matrices are
+ static size_t DefaultLDA(const Arguments<T> &) { return 1; } // N/A for this routine
+ static size_t DefaultLDB(const Arguments<T> &) { return 1; } // N/A for this routine
+ static size_t DefaultLDC(const Arguments<T> &) { return 1; } // N/A for this routine
+
+ // Describes which transpose options are relevant for this routine
+ using Transposes = std::vector<Transpose>;
+ static Transposes GetATransposes(const Transposes &) { return {}; } // N/A for this routine
+ static Transposes GetBTransposes(const Transposes &) { return {}; } // N/A for this routine
+
+ // Describes how to prepare the input data
+ static void PrepareData(const Arguments<T>&, Queue&, const int, std::vector<T>&,
+ std::vector<T>&, std::vector<T>&, std::vector<T>&, std::vector<T>&,
+ std::vector<T>&, std::vector<T>&) {} // N/A for this routine
+
+ // Describes how to run the CLBlast routine
+ static StatusCode RunRoutine(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) {
+ auto queue_plain = queue();
+ auto event = cl_event{};
+ auto status = Im2col<T>(args.channels, args.height, args.width,
+ args.kernel_h, args.kernel_w,
+ args.pad_h, args.pad_w,
+ args.stride_h, args.stride_w,
+ args.dilation_h, args.dilation_w,
+ buffers.a_mat(), args.a_offset,
+ buffers.b_mat(), args.b_offset,
+ &queue_plain, &event);
+ if (status == StatusCode::kSuccess) { clWaitForEvents(1, &event); clReleaseEvent(event); }
+ return status;
+ }
+
+ // 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) {
+ 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, BuffersHost<T> &buffers_host, Queue&) {
+ return RunReference(args, buffers_host);
+ }
+ static StatusCode RunReference3(const Arguments<T> &, BuffersCUDA<T> &, Queue &) {
+ return StatusCode::kUnknownError;
+ }
+
+ // Describes how to download the results of the computation (more importantly: which buffer)
+ static std::vector<T> DownloadResult(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) {
+ std::vector<T> result(args.b_size, static_cast<T>(0));
+ buffers.b_mat.Read(queue, args.b_size, result);
+ return result;
+ }
+
+ // Describes how to compute the indices of the result buffer
+ static size_t ResultID1(const Arguments<T> &args) { return args.kernel_h * args.kernel_w; }
+ static size_t ResultID2(const Arguments<T> &args) { return NumPatches(args); }
+ static size_t GetResultIndex(const Arguments<T> &args, const size_t id1, const size_t id2) {
+ return id1 + args.kernel_h * args.kernel_w * id2 + args.b_offset;
+ }
+
+ // Describes how to compute performance metrics
+ static size_t GetFlops(const Arguments<T> &args) {
+ return 1;
+ }
+ static size_t GetBytes(const Arguments<T> &args) {
+ return (1) * sizeof(T);
+ }
+};
+
+// =================================================================================================
+} // namespace clblast
+
+// CLBLAST_TEST_ROUTINES_XIM2COL_H_
+#endif
diff --git a/test/routines/levelx/xomatcopy.hpp b/test/routines/levelx/xomatcopy.hpp
index 4638b61c..2736cf75 100644
--- a/test/routines/levelx/xomatcopy.hpp
+++ b/test/routines/levelx/xomatcopy.hpp
@@ -114,7 +114,7 @@ class TestXomatcopy {
static size_t DefaultLDB(const Arguments<T> &args) { return args.m; }
static size_t DefaultLDC(const Arguments<T> &) { return 1; } // N/A for this routine
- // Describes which omatcopyose options are relevant for this routine
+ // Describes which transpose options are relevant for this routine
using Transposes = std::vector<Transpose>;
static Transposes GetATransposes(const Transposes &all) { return all; }
static Transposes GetBTransposes(const Transposes &) { return {}; } // N/A for this routine