// ================================================================================================= // 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 common kernels shared among different BLAS functions. This file contains // kernels to transpose matrices. // // ================================================================================================= // 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. #ifndef TRA_DIM #define TRA_DIM 8 // Number of local threads in the two dimensions (x,y) #endif #ifndef TRA_WPT #define TRA_WPT 1 // Work per thread in one dimension and vector-width in the other #endif #ifndef TRA_PAD #define TRA_PAD 0 // Padding of the local memory to avoid bank-conflicts #endif #ifndef TRA_SHUFFLE #define TRA_SHUFFLE 0 // Shuffling of the global indices to avoid global memory bank-conflicts #endif // ================================================================================================= // Data-widths #if TRA_WPT == 1 typedef real realT; #elif TRA_WPT == 2 typedef real2 realT; #elif TRA_WPT == 4 typedef real4 realT; #elif TRA_WPT == 8 typedef real8 realT; #elif TRA_WPT == 16 typedef real16 realT; #endif // ================================================================================================= // Transposes and copies a matrix. Requires both matrices to be of the same dimensions and without // offset. A more general version is available in 'padtranspose.opencl'. __attribute__((reqd_work_group_size(TRA_DIM, TRA_DIM, 1))) __kernel void TransposeMatrix(const int ld, __global const realT* restrict src, __global realT* dest) { // Sets the group identifiers. They might be 'shuffled' around to distribute work in a different // way over workgroups, breaking memory-bank dependencies. const int gid0 = get_group_id(0); #if TRA_SHUFFLE == 1 const int gid1 = (get_group_id(0) + get_group_id(1)) % get_num_groups(0); #else const int gid1 = get_group_id(1); #endif // Local memory to store a tile of the matrix (for coalescing) __local realT tile[TRA_WPT*TRA_DIM][TRA_DIM + TRA_PAD]; // Loops over the work per thread #pragma unroll for (int w_one=0; w_one