// ================================================================================================= // 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 in various ways, including: // 1) transposing into a larger matrix by adding padding // 2) transposing into a smaller matrix by optionally removing padding. This is the general version // without restrictions, see the 'transpose.opencl' file for a faster but more restricted // transpose kernel. // // ================================================================================================= // 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"( // ================================================================================================= // Transposes a matrix from source to destination. The output is padded with zero values in case the // destination matrix dimensions are larger than the transposed source matrix dimensions. INLINE_FUNC void _TransposePadMatrix(__local real* tile, const int src_one, const int src_two, const int src_ld, const int src_offset, __global const real* restrict src, const int dest_one, const int dest_two, const int dest_ld, const int dest_offset, __global real* dest, const real alpha, const int do_conjugate) { // Loop over the work per thread #pragma unroll for (int w_one=0; w_one= id_dest_two); } else if (lower == 1) { condition = (id_dest_one <= id_dest_two); } #endif if (condition) { // Stores the transposed value in the destination matrix if ((id_dest_one < dest_one) && (id_dest_two < dest_two)) { const int tile_id0 = get_local_id(1)*PADTRA_WPT + w_one; const int tile_id1 = get_local_id(0)*PADTRA_WPT + w_two; real value = tile[tile_id1 * (PADTRA_WPT*PADTRA_TILE + PADTRA_PAD) + tile_id0]; if (diagonal_imag_zero == 1 && id_dest_one == id_dest_two) { ImagToZero(value); } Multiply(dest[id_dest_two*dest_ld + id_dest_one + dest_offset], alpha, value); } } } } } // Interface to the above function __kernel __attribute__((reqd_work_group_size(PADTRA_TILE, PADTRA_TILE, 1))) void TransposeMatrix(const int src_one, const int src_two, const int src_ld, const int src_offset, __global const real* restrict src, const int dest_one, const int dest_two, const int dest_ld, const int dest_offset, __global real* dest, const real_arg arg_alpha, const int upper, const int lower, const int diagonal_imag_zero) { const real alpha = GetRealArg(arg_alpha); __local real tile[(PADTRA_WPT*PADTRA_TILE) * (PADTRA_WPT*PADTRA_TILE + PADTRA_PAD)]; _TransposeMatrix(tile, src_one, src_two, src_ld, src_offset, src, dest_one, dest_two, dest_ld, dest_offset, dest, alpha, upper, lower, diagonal_imag_zero); } // ================================================================================================= #if defined(ROUTINE_GEMMBATCHED) // Batched version of the above __kernel __attribute__((reqd_work_group_size(PADTRA_TILE, PADTRA_TILE, 1))) void TransposePadMatrixBatched(const int src_one, const int src_two, const int src_ld, const __constant int* src_offsets, __global const real* restrict src, const int dest_one, const int dest_two, const int dest_ld, const __constant int* dest_offsets, __global real* dest, const int do_conjugate) { const int batch = get_group_id(2); const int src_offset = src_offsets[batch]; const int dest_offset = dest_offsets[batch]; real alpha; SetToOne(alpha); __local real tile[(PADTRA_WPT*PADTRA_TILE) * (PADTRA_WPT*PADTRA_TILE + PADTRA_PAD)]; _TransposePadMatrix(tile, src_one, src_two, src_ld, src_offset, src, dest_one, dest_two, dest_ld, dest_offset, dest, alpha, do_conjugate); } // Batched version of the above __kernel __attribute__((reqd_work_group_size(PADTRA_TILE, PADTRA_TILE, 1))) void TransposeMatrixBatched(const int src_one, const int src_two, const int src_ld, const __constant int* src_offsets, __global const real* restrict src, const int dest_one, const int dest_two, const int dest_ld, const __constant int* dest_offsets, __global real* dest) { const int batch = get_group_id(2); const int src_offset = src_offsets[batch]; const int dest_offset = dest_offsets[batch]; real alpha; SetToOne(alpha); __local real tile[(PADTRA_WPT*PADTRA_TILE) * (PADTRA_WPT*PADTRA_TILE + PADTRA_PAD)]; _TransposeMatrix(tile, src_one, src_two, src_ld, src_offset, src, dest_one, dest_two, dest_ld, dest_offset, dest, alpha, 0, 0, 0); } #endif // ================================================================================================= // End of the C++11 raw string literal )" // =================================================================================================