// ================================================================================================= // 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 // // This file provides declarations for the common test utility functions (performance clients and // correctness testers). // // ================================================================================================= #ifndef CLBLAST_TEST_UTILITIES_H_ #define CLBLAST_TEST_UTILITIES_H_ #include #include #include #include #include #include "utilities/utilities.hpp" namespace clblast { // ================================================================================================= // The client-specific arguments in string form constexpr auto kArgCompareclblas = "clblas"; constexpr auto kArgComparecblas = "cblas"; constexpr auto kArgComparecublas = "cublas"; constexpr auto kArgStepSize = "step"; constexpr auto kArgNumSteps = "num_steps"; constexpr auto kArgWarmUp = "warm_up"; constexpr auto kArgTunerFiles = "tuner_files"; // The test-specific arguments in string form constexpr auto kArgFullTest = "full_test"; constexpr auto kArgVerbose = "verbose"; // ================================================================================================= // Returns whether a scalar is close to zero template bool IsCloseToZero(const T value); // ================================================================================================= // Structure containing all possible buffers for test clients template struct Buffers { Buffer x_vec; Buffer y_vec; Buffer a_mat; Buffer b_mat; Buffer c_mat; Buffer ap_mat; Buffer scalar; Buffer scalar_uint; }; template struct BuffersHost { std::vector x_vec; std::vector y_vec; std::vector a_mat; std::vector b_mat; std::vector c_mat; std::vector ap_mat; std::vector scalar; std::vector scalar_uint; }; // ================================================================================================= template T ComplexConjugate(const T value); // ================================================================================================= // Converts a value (e.g. an integer) to a string. This also covers special cases for CLBlast // data-types such as the Layout and Transpose data-types. template std::string ToString(T value); // ================================================================================================= // Copies buffers from the OpenCL device to the host template void DeviceToHost(const Arguments &args, Buffers &buffers, BuffersHost &buffers_host, Queue &queue, const std::vector &names); // Copies buffers from the host to the OpenCL device template void HostToDevice(const Arguments &args, Buffers &buffers, BuffersHost &buffers_host, Queue &queue, const std::vector &names); // ================================================================================================= // Conversion between half and single-precision std::vector HalfToFloatBuffer(const std::vector& source); void FloatToHalfBuffer(std::vector& result, const std::vector& source); // As above, but now for OpenCL data-types instead of std::vectors #ifdef OPENCL_API Buffer HalfToFloatBuffer(const Buffer& source, RawCommandQueue queue_raw); void FloatToHalfBuffer(Buffer& result, const Buffer& source, RawCommandQueue queue_raw); #endif // ================================================================================================= // Creates a buffer but don't test for validity. That's the reason this is not using the clpp11.h or // cupp11.h interface. template Buffer CreateInvalidBuffer(const Context& context, const size_t size) { #ifdef OPENCL_API auto raw_buffer = clCreateBuffer(context(), CL_MEM_READ_WRITE, size * sizeof(T), nullptr, nullptr); #elif CUDA_API CUdeviceptr raw_buffer; cuMemAlloc(&raw_buffer, size * sizeof(T)); #endif return Buffer(raw_buffer); } // ================================================================================================= using BestParameters = std::unordered_map; using BestParametersCollection = std::unordered_map; void OverrideParametersFromJSONFiles(const std::vector& file_names, const RawDeviceID device, const Precision precision); void GetBestParametersFromJSONFile(const std::string& file_name, BestParametersCollection& all_parameters, const Precision precision); // ================================================================================================= } // namespace clblast // CLBLAST_TEST_UTILITIES_H_ #endif