summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Nugteren <web@cedricnugteren.nl>2017-09-23 11:43:19 +0200
committerGitHub <noreply@github.com>2017-09-23 11:43:19 +0200
commit0dd2ca9283285f4144e4b5b7b809c31d1a70e856 (patch)
treea4298c378b51776dd4695b2646d6357e0d711312
parent44b59ec0cb6ccbb3d2b71939ed7c5ebfa1de7c4e (diff)
parent65c492edf6ded8b259febb71ae92b3aa10607494 (diff)
Merge pull request #192 from CNugteren/diagnostics_helper
Diagnostics helper
-rw-r--r--CHANGELOG1
-rw-r--r--CMakeLists.txt7
-rw-r--r--test/diagnostics.cpp100
3 files changed, 108 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index a62c040e..32c0be3a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -5,6 +5,7 @@ Development (next version)
- The tuners can now distinguish between different AMD GPU board names of the same architecture
- The tuners can now use particle-swarm optimisation to search more efficiently (thanks to 'mcian')
- Further improved compilation time of database.cpp
+- Added a small diagnostics helper executable
- Various minor fixes and enhancements
- Added tuned parameters for various devices (see README)
- Added non-BLAS routines:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5d86d05d..3140905c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -497,6 +497,13 @@ if(TESTS)
add_test(clblast_test_${MISC_TEST} clblast_test_${MISC_TEST})
endforeach()
+ # CLBlast diagnostics
+ add_executable(clblast_test_diagnostics ${TESTS_COMMON} test/diagnostics.cpp)
+ target_link_libraries(clblast_test_diagnostics clblast ${REF_LIBRARIES} ${OPENCL_LIBRARIES})
+ target_include_directories(clblast_test_diagnostics PUBLIC
+ $<TARGET_PROPERTY:clblast,INTERFACE_INCLUDE_DIRECTORIES>
+ ${clblast_SOURCE_DIR} ${REF_INCLUDES})
+
# Adds 'alltests' target: runs all tests
set(ALLTESTS )
set(ALLTESTSDEPENDS )
diff --git a/test/diagnostics.cpp b/test/diagnostics.cpp
new file mode 100644
index 00000000..6872ed6f
--- /dev/null
+++ b/test/diagnostics.cpp
@@ -0,0 +1,100 @@
+
+// =================================================================================================
+// 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 contains 'clinfo' like diagnostics specific for CLBlast (debugging)
+//
+// =================================================================================================
+
+#include <cstdio>
+#include <chrono>
+#include <algorithm>
+
+#include "utilities/utilities.hpp"
+
+namespace clblast {
+// =================================================================================================
+
+template<typename F>
+double TimeFunction(const size_t num_runs, F const &function) {
+ auto timings = std::vector<double>(num_runs);
+ for (auto &timing: timings) {
+ const auto start_time = std::chrono::steady_clock::now();
+ function();
+ const auto elapsed_time = std::chrono::steady_clock::now() - start_time;
+ timing = std::chrono::duration<double,std::milli>(elapsed_time).count();
+ }
+ return *std::min_element(timings.begin(), timings.end());
+
+}
+
+void OpenCLDiagnostics(int argc, char *argv[]) {
+ auto arguments = RetrieveCommandLineArguments(argc, argv);
+
+ // Retrieves the arguments
+ auto help = std::string{"Options given/available:\n"};
+ const auto platform_id = GetArgument(arguments, help, kArgPlatform, ConvertArgument(std::getenv("CLBLAST_PLATFORM"), size_t{0}));
+ const auto device_id = GetArgument(arguments, help, kArgDevice, ConvertArgument(std::getenv("CLBLAST_DEVICE"), size_t{0}));
+ fprintf(stdout, "\n* %s\n", help.c_str());
+
+ // Initializes OpenCL
+ const auto platform = Platform(platform_id);
+ const auto device = Device(platform, device_id);
+ const auto context = Context(device);
+ auto queue = Queue(context, device);
+
+ // Finds device information
+ const auto device_type = GetDeviceType(device);
+ const auto device_vendor = GetDeviceVendor(device);
+ const auto device_architecture = GetDeviceArchitecture(device);
+ const auto device_name = GetDeviceName(device);
+ printf("\n --- OpenCL device naming:\n");
+ printf("* Device type %s\n", device.Type().c_str());
+ printf("* Device name %s\n", device.Name().c_str());
+ printf("* Platform vendor %s\n", platform.Vendor().c_str());
+ printf("* Platform version %s\n", platform.Version().c_str());
+
+ // Prints the CLBlast specific device names
+ printf("\n --- CLBlast device naming:\n");
+ printf("* Device type %s\n", device_type.c_str());
+ printf("* Device name %s\n", device_name.c_str());
+ printf("* Device vendor %s\n", device_vendor.c_str());
+ printf("* Device architecture %s\n", device_architecture.c_str());
+
+ // Selected OpenCL properties
+ printf("\n --- OpenCL device properties:\n");
+ printf("* Max work group size %zu\n", device.MaxWorkGroupSize());
+ printf("* Max work item dimensions %zu\n", device.MaxWorkItemDimensions());
+ const auto max_work_item_sizes = device.MaxWorkItemSizes();
+ for (auto i = size_t{0}; i < max_work_item_sizes.size(); ++i) {
+ printf("* - Max work item size #%zu %zu\n", i, max_work_item_sizes[i]);
+ }
+ printf("* Local memory size %zuKB\n", device.LocalMemSize());
+ printf("* Extensions:\n%s\n", device.Capabilities().c_str());
+
+ // Simple OpenCL benchmarking
+ constexpr auto kNumRuns = 20;
+ printf("\n --- Some OpenCL library benchmarks (functions from clpp11.h):\n");
+ printf("* queue.GetContext() %.4lf ms\n", TimeFunction(kNumRuns, [&](){queue.GetContext();} ));
+ printf("* queue.GetDevice() %.4lf ms\n", TimeFunction(kNumRuns, [&](){queue.GetDevice();} ));
+ printf("* device.Name() %.4lf ms\n", TimeFunction(kNumRuns, [&](){device.Name();} ));
+ printf("* Buffer<float>(context, 1024) %.4lf ms\n", TimeFunction(kNumRuns, [&](){Buffer<float>(context, 1024);} ));
+
+ printf("\n");
+}
+
+// =================================================================================================
+} // namespace clblast
+
+// Main function (not within the clblast namespace)
+int main(int argc, char *argv[]) {
+ clblast::OpenCLDiagnostics(argc, argv);
+ return 0;
+}
+
+// =================================================================================================