// ================================================================================================= // 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 contains the Xgemv kernel (fast versions) for matrix-vector multiplication. // // ================================================================================================= // Enables loading of this file using the C++ pre-processor's #include (C++11 standard raw string // literal). Comment-out this line for syntax-highlighting when developing. R"( // ================================================================================================= // Parameters set by the tuner or by the database. Here they are given a basic default value in case // this kernel file is used outside of the CLBlast library. // 1: For the full version, see 'xgemv.opencl' // 2: For the fast version #ifndef WGS2 #define WGS2 64 // The local work-group size #endif #ifndef WPT2 #define WPT2 1 // The amount of work-per-thread #endif #ifndef VW2 #define VW2 1 // Vector width of matrix A loads #endif // 3: For the fast rotated version #ifndef WGS3 #define WGS3 64 // The local work-group size #endif #ifndef WPT3 #define WPT3 1 // The tile-size #endif #ifndef VW3 #define VW3 1 // Vector width of matrix A loads #endif // ================================================================================================= // Data-widths for the 'fast' kernel #if VW2 == 1 typedef real realVF; #elif VW2 == 2 typedef real2 realVF; #elif VW2 == 4 typedef real4 realVF; #elif VW2 == 8 typedef real8 realVF; #elif VW2 == 16 typedef real16 realVF; #endif // Data-widths for the 'fast' kernel with rotated matrix #if VW3 == 1 typedef real realVFR; #elif VW3 == 2 typedef real2 realVFR; #elif VW3 == 4 typedef real4 realVFR; #elif VW3 == 8 typedef real8 realVFR; #elif VW3 == 16 typedef real16 realVFR; #endif // ================================================================================================= // Loads a vector input value INLINE_FUNC realVF LoadMatrixAVF(const __global realVF* restrict agm, const int x, const int y, const int a_ld) { return agm[a_ld*y + x]; } // ================================================================================================= // Faster version of the kernel, assuming that: // --> 'm' and 'n' are multiples of WGS2 // --> 'a_offset' is 0 // --> 'a_ld' is a multiple of VW2 // --> 'a_rotated' is 0 // --> 'do_conjugate' is 0 #if RELAX_WORKGROUP_SIZE == 1 __kernel #else __kernel __attribute__((reqd_work_group_size(WGS2, 1, 1))) #endif void XgemvFast(const int m, const int n, const real_arg arg_alpha, const real_arg arg_beta, const int a_rotated, const __global realVF* restrict agm, const int a_offset, const int a_ld, const __global real* restrict xgm, const int x_offset, const int x_inc, __global real* ygm, const int y_offset, const int y_inc, const int do_conjugate, const int parameter, const int kl_unused, const int ku_unused) { const real alpha = GetRealArg(arg_alpha); const real beta = GetRealArg(arg_beta); // Local memory for the vector X __local real xlm[WGS2]; // Initializes the accumulation registers #pragma promote_to_registers real acc2[WPT2]; #pragma unroll for (int _w = 0; _w < WPT2; _w += 1) { SetToZero(acc2[_w]); } // Loops over work-group sized portions of the work for (int kwg=0; kwg 'm' and 'n' are multiples of WGS3 // --> 'a_offset' is 0 // --> 'a_ld' is a multiple of VW3 // --> 'a_rotated' is 1 // --> 'do_conjugate' is 0 #if RELAX_WORKGROUP_SIZE == 1 __kernel #else __kernel __attribute__((reqd_work_group_size(WGS3, 1, 1))) #endif void XgemvFastRot(const int m, const int n, const real_arg arg_alpha, const real_arg arg_beta, const int a_rotated, const __global realVFR* restrict agm, const int a_offset, const int a_ld, const __global real* restrict xgm, const int x_offset, const int x_inc, __global real* ygm, const int y_offset, const int y_inc, const int do_conjugate, const int parameter, const int kl_unused, const int ku_unused) { const real alpha = GetRealArg(arg_alpha); const real beta = GetRealArg(arg_beta); // Local memory to store a tile of the matrix (for coalescing) __local real tile[WPT3][WGS3]; const int lid = get_local_id(0); const int lid_mod = lid % (WPT3/VW3); const int lid_div = lid / (WPT3/VW3); // Local memory for the vector X __local real xlm[WPT3]; // Initializes the accumulation register real acc3; SetToZero(acc3); // Loops over tile-sized portions of the work for (int kwg=0; kwg