okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
23b3dfc2c
main
1//==---- blas_utils.hpp----------------------------*- C++ -*----------------==// 2// 3// Copyright (C) Intel Corporation 4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 5// See https://llvm.org/LICENSE.txt for license information. 6// 7//===----------------------------------------------------------------------===// 8 9#ifndef __DPCT_BLAS_UTILS_HPP__ 10#define __DPCT_BLAS_UTILS_HPP__ 11 12#include "compat_service.hpp" 13#include "lib_common_utils.hpp" 14 15#include "detail/blas_utils_detail.hpp" 16 17namespace dpct { 18namespace blas { 19 20/// Parameter input/output properties are: 21/// in: input parameter 22/// out: output parameter 23/// in_out: input and output parameter 24enum class parameter_inout_prop {in ,out ,in_out }; 25 26/// parameter_wrapper_t is a class to wrap the parameter to fit the oneMKL 27/// interface. 28/// E.g., 29/// \code 30/// void foo(sycl::queue q, int *res) { 31/// // Declare the wrapper. 32/// parameter_wrapper_t<std::int64_t, int, parameter_inout_prop::out> 33/// res_wrapper(q, res); 34/// // parameter_wrapper_t::get_ptr() is passed as a parameter. The result is 35/// // saved into the wrapper. 36/// oneapi::mkl::...(q, ..., res_wrapper.get_ptr()); 37/// // The action to copy the result in the wrapper to the original variable 38/// // is submitted when destructing the wrapper automatically. 39/// } 40/// \endcode 41/// \tparam target_t Data type to fit oneMKL parameter data type. E.g., 42/// get_ptr() returns \tparam target_t data type and can be used as oneMKL 43/// parameter with USM memory configuration. 44/// \tparam source_t Data type of the original parameter. 45/// \tparam inout_prop The input/output property of the parameter. 46template < typename target_t ,typename source_t ,parameter_inout_prop inout_prop > 47class parameter_wrapper_t 48 :public detail::parameter_wrapper_base_t < target_t ,source_t > { 49 static_assert(inout_prop == parameter_inout_prop::out && 50"Only parameter_inout_prop::out is supported if " 51"target_t and source_t are not same." ); 52using base_t = detail::parameter_wrapper_base_t < target_t ,source_t > ; 53using base_t::_q ; 54using base_t::_source ; 55using base_t::_source_attribute ; 56using base_t::_target ; 57 58public : 59/// Constructor. Malloc the wrapper memory. 60/// \param q The queue used for internal malloc and memcpy 61/// \param source The original parameter 62parameter_wrapper_t (sycl::queue q ,source_t * source ) :base_t (q ,source ,1 ) {} 63/// Destructor. Copy back content from wrapper memory to original memory 64 ~parameter_wrapper_t () { 65#ifdef DPCT_USM_LEVEL_NONE 66if (_source_attribute == 67 ::dpct::cs::detail::pointer_access_attribute::device_only ) { 68_q .submit ([& ](sycl::handler & cgh ) { 69auto from_acc = dpct::get_buffer < target_t > (_target ) 70 .template get_access < sycl::access_mode::read > (cgh ); 71auto to_acc = dpct::get_buffer < source_t > (_source ) 72 .template get_access < sycl::access_mode::write > (cgh ); 73cgh .single_task < ::dpct::cs::kernel_name < 74class parameter_wrapper_copyback ,target_t ,source_t >> ( 75 [= ]() {to_acc [0 ]= static_cast < source_t > (from_acc [0 ]); }); 76 }); 77 }else { 78source_t temp = 79static_cast < source_t > (dpct::get_host_ptr < target_t > (_target )[0 ]); 80* _source = temp ; 81 } 82#else 83if (_source_attribute == 84 ::dpct::cs::detail::pointer_access_attribute::device_only ) { 85_q .template single_task < ::dpct::cs::kernel_name < 86class parameter_wrapper_copyback ,target_t ,source_t >> ( 87 [t = _target ,s = _source ]() {* s = static_cast < source_t > (* t ); }); 88 }else { 89target_t temp ; 90_q .memcpy (& temp ,_target ,sizeof (target_t )).wait (); 91* _source = static_cast < source_t > (temp ); 92 } 93#endif 94 } 95/// Get the target memory of the wrapper to represent the wrapped variable 96target_t * get_ptr () {return _target ; } 97}; 98 99/// parameter_wrapper_t is a class to wrap the parameter to fit the oneMKL 100/// interface. 101/// E.g., 102/// \code 103/// void foo(sycl::queue q, int *params, int ele_num) { 104/// // Declare the wrapper. 105/// parameter_wrapper_t<float, parameter_inout_prop::in_out> params_wrapper( 106/// q, params, ele_num); 107/// // parameter_wrapper_t::get_ptr() is passed as a parameter. The result is 108/// // saved into the wrapper. 109/// oneapi::mkl::...(q, ..., params_wrapper.get_ptr()); 110/// // The action to copy the result in the wrapper to the original variable 111/// // is submitted when destructing the wrapper automatically. 112/// } 113/// \endcode 114/// \tparam target_t Data type to fit oneMKL parameter data type. E.g., 115/// get_ptr() returns \tparam target_t data type and can be used as oneMKL 116/// parameter with USM memory configuration. 117/// \tparam inout_prop The input/output property of the parameter. 118template < typename target_t ,parameter_inout_prop inout_prop > 119class parameter_wrapper_t < target_t ,target_t ,inout_prop > 120 :public detail::parameter_wrapper_base_t < target_t ,target_t > { 121using base_t = detail::parameter_wrapper_base_t < target_t ,target_t > ; 122using base_t::_ele_num ; 123using base_t::_need_free ; 124using base_t::_q ; 125using base_t::_source ; 126using base_t::_source_attribute ; 127using base_t::_target ; 128 129public : 130/// Constructor. Malloc the wrapper memory. 131/// \param q The queue used for internal malloc and memcpy 132/// \param source The original parameter 133/// \param ele_num Element number in \p source 134parameter_wrapper_t (sycl::queue q ,target_t * source ,size_t ele_num = 1 ) 135 :base_t (q ,source ,ele_num ) { 136if constexpr (inout_prop != parameter_inout_prop::out ) { 137if (_need_free ) { 138 ::dpct::cs::memcpy (_q ,_target ,_source ,sizeof (target_t )* _ele_num , 139 ::dpct::cs::memcpy_direction::automatic ); 140 } 141 } 142 } 143 144/// Constructor. Only vaild for parameter_inout_prop::in. 145/// \param q The queue used for internal malloc and memcpy 146/// \param source The original parameter 147/// \param ele_num Element number in \p source 148template < parameter_inout_prop prop = inout_prop > 149parameter_wrapper_t ( 150 sycl::queue q ,const target_t * source ,size_t ele_num = 1 , 151typename std::enable_if < prop == parameter_inout_prop::in > ::type * = 0 ) 152 :parameter_wrapper_t (q ,const_cast < target_t *> (source ),ele_num ) {} 153 154/// Destructor. Copy back content from wrapper memory to original memory 155 ~parameter_wrapper_t () { 156if constexpr (inout_prop != parameter_inout_prop::in ) { 157if (_need_free ) { 158 sycl::event e = ::dpct::cs::memcpy ( 159_q ,_source ,_target ,sizeof (target_t )* _ele_num , 160 ::dpct::cs::memcpy_direction::automatic ); 161 (void )e ; 162if (_source_attribute == 163 ::dpct::cs::detail::pointer_access_attribute::host_only ) 164e .wait (); 165 } 166 } 167 } 168/// Get the target memory of the wrapper to represent the wrapped variable 169target_t * get_ptr () {return _target ; } 170}; 171 172using wrapper_int_to_int64_out = 173parameter_wrapper_t < std::int64_t ,int , parameter_inout_prop::out > ; 174using wrapper_int64_out = 175parameter_wrapper_t < std::int64_t , std::int64_t , parameter_inout_prop::out > ; 176using wrapper_float_out = 177parameter_wrapper_t < float ,float , parameter_inout_prop::out > ; 178using wrapper_double_out = 179parameter_wrapper_t < double ,double , parameter_inout_prop::out > ; 180using wrapper_float2_out = 181parameter_wrapper_t < sycl::float2 , sycl::float2 , parameter_inout_prop::out > ; 182using wrapper_double2_out = parameter_wrapper_t < sycl::double2 , sycl::double2 , 183 parameter_inout_prop::out > ; 184using wrapper_float_inout = 185parameter_wrapper_t < float ,float , parameter_inout_prop::in_out > ; 186using wrapper_double_inout = 187parameter_wrapper_t < double ,double , parameter_inout_prop::in_out > ; 188using wrapper_float2_inout = parameter_wrapper_t < sycl::float2 , sycl::float2 , 189 parameter_inout_prop::in_out > ; 190using wrapper_double2_inout = parameter_wrapper_t < sycl::double2 , sycl::double2 , 191 parameter_inout_prop::in_out > ; 192using wrapper_float_in = 193parameter_wrapper_t < float ,float , parameter_inout_prop::in > ; 194using wrapper_double_in = 195parameter_wrapper_t < double ,double , parameter_inout_prop::in > ; 196 197/// Copy matrix data synchronously. The default leading dimension is column. 198/// \param [out] to_ptr A pointer points to the destination location. 199/// \param [in] from_ptr A pointer points to the source location. 200/// \param [in] to_ld The leading dimension the destination matrix. 201/// \param [in] from_ld The leading dimension the source matrix. 202/// \param [in] rows The number of rows of the source matrix. 203/// \param [in] cols The number of columns of the source matrix. 204/// \param [in] elem_size The element size in bytes. 205/// \param [in] direction The direction of the data copy. 206/// \param [in] queue The queue where the routine should be executed. 207/// \param [in] deps A list of events to wait for before starting copy. 208inline void 209matrix_mem_copy_sync (void * to_ptr ,const void * from_ptr , std::int64_t to_ld , 210 std::int64_t from_ld , std::int64_t rows , std::int64_t cols , 211 std::int64_t elem_size , 212 ::dpct::cs::memcpy_direction direction = 213 ::dpct::cs::memcpy_direction::automatic , 214 sycl::queue & queue = ::dpct::cs::get_default_queue (), 215const std::vector < sycl::event > & deps = {}) { 216if ( to_ptr == from_ptr && to_ld == from_ld ) 217return ; 218if ( to_ld == from_ld ) { 219size_t copy_size = elem_size * (( cols - 1 ) * (size_t) to_ld + rows ); 220::dpct::cs:: memcpy ( queue , to_ptr , from_ptr , copy_size , direction , deps ) 221. wait (); 222} else { 223sycl::event:: wait (::dpct::cs:: memcpy ( 224queue , to_ptr , from_ptr , elem_size * to_ld , elem_size * from_ld , 225elem_size * rows , cols , direction , deps )); 226} 227} 228/// Copy matrix data asynchronously. The default leading dimension is column. 229/// \return Output event to wait on to ensure copy is complete. 230/// \param [out] to_ptr A pointer points to the destination location. 231/// \param [in] from_ptr A pointer points to the source location. 232/// \param [in] to_ld The leading dimension the destination matrix. 233/// \param [in] from_ld The leading dimension the source matrix. 234/// \param [in] rows The number of rows of the source matrix. 235/// \param [in] cols The number of columns of the source matrix. 236/// \param [in] elem_size The element size in bytes. 237/// \param [in] direction The direction of the data copy. 238/// \param [in] queue The queue where the routine should be executed. 239/// \param [in] deps A list of events to wait for before starting copy. 240inline sycl::event 241matrix_mem_copy_async (void * to_ptr , const void * from_ptr , std::int64_t to_ld , 242std::int64_t from_ld , std::int64_t rows , 243std::int64_t cols , std::int64_t elem_size , 244::dpct::cs::memcpy_direction direction = 245::dpct::cs::memcpy_direction:: automatic , 246sycl::queue & queue = ::dpct::cs:: get_default_queue (), 247const std::vector < sycl::event > & deps = {}) { 248if ( to_ptr == from_ptr && to_ld == from_ld ) 249return sycl:: event (); 250if ( to_ld == from_ld ) { 251size_t copy_size = elem_size * (( cols - 1 ) * (size_t) to_ld + rows ); 252return ::dpct::cs:: memcpy ( queue , to_ptr , from_ptr , copy_size , direction , 253deps ); 254} 255auto events = ::dpct::cs:: memcpy ( queue , to_ptr , from_ptr , elem_size * to_ld , 256elem_size * from_ld , elem_size * rows , cols , 257direction , deps ); 258return queue . single_task ( events , [] {}); 259} 260 261/// Copy matrix data. The default leading dimension is column. 262/// \param [out] to_ptr A pointer points to the destination location. 263/// \param [in] from_ptr A pointer points to the source location. 264/// \param [in] to_ld The leading dimension the destination matrix. 265/// \param [in] from_ld The leading dimension the source matrix. 266/// \param [in] rows The number of rows of the source matrix. 267/// \param [in] cols The number of columns of the source matrix. 268/// \param [in] elem_size The element size in bytes. 269/// \param [in] direction The direction of the data copy. 270/// \param [in] queue The queue where the routine should be executed. 271/// \param [in] async If this argument is true, the return of the function 272/// does NOT guarantee the copy is completed. 273inline void 274matrix_mem_copy (void * to_ptr , const void * from_ptr , std::int64_t to_ld , 275std::int64_t from_ld , std::int64_t rows , std::int64_t cols , 276std::int64_t elem_size , 277::dpct::cs::memcpy_direction direction = 278::dpct::cs::memcpy_direction:: automatic , 279sycl::queue & queue = ::dpct::cs:: get_default_queue (), 280bool async = false) { 281if ( async ) 282matrix_mem_copy_async ( to_ptr , from_ptr , to_ld , from_ld , rows , cols , 283elem_size , direction , queue ); 284else 285matrix_mem_copy_sync ( to_ptr , from_ptr , to_ld , from_ld , rows , cols , 286elem_size , direction , queue ); 287} 288 289enum class math_mode : int { 290mm_default , 291mm_tf32 , 292}; 293 294using ::dpct:: compute_type ; 295 296class descriptor { 297public : 298void set_queue (::dpct::cs::queue_ptr q_ptr ) noexcept { _queue_ptr = q_ptr ; } 299sycl::queue & get_queue () noexcept { return * _queue_ptr ; } 300void set_math_mode (math_mode mm ) noexcept { _mm = mm ; } 301math_mode get_math_mode () const noexcept { return _mm ; } 302static inline void set_saved_queue (::dpct::cs::queue_ptr q_ptr ) noexcept { 303_saved_queue_ptr = q_ptr ; 304} 305static inline sycl::queue & get_saved_queue () noexcept { 306if (! _saved_queue_ptr ) _saved_queue_ptr = & ::dpct::cs:: get_default_queue (); 307return * _saved_queue_ptr ; 308} 309 310private : 311::dpct::cs::queue_ptr _queue_ptr = & ::dpct::cs:: get_default_queue (); 312math_mode _mm = math_mode:: mm_default ; 313static inline ::dpct::cs::queue_ptr _saved_queue_ptr = nullptr ; 314}; 315 316using descriptor_ptr = descriptor * ; 317} // namespace blas 318 319/// Get the value of \p s. 320/// Copy the data to host synchronously, then return the data. 321/// \param [in] p The pointer points the data. 322/// \param [in] q The queue where the memory copy should be executed. 323template < typename T > inline T get_value ( const T * s , sycl::queue & q ) { 324return detail:: get_value ( s , q ); 325} 326template < typename T > 327inline std::complex < T > get_value ( const sycl::vec < T, 2 > * s , sycl::queue & q ) { 328return detail:: get_value ( s , q ); 329} 330 331inline oneapi::mkl::transpose get_transpose (int t ) { 332if ( t == 0 ) { 333return oneapi::mkl::transpose:: nontrans ; 334} else if ( t == 1 ) { 335return oneapi::mkl::transpose:: trans ; 336} else { 337return oneapi::mkl::transpose:: conjtrans ; 338} 339} 340 341/// Computes the LU factorizations of a batch of general matrices. 342/// \param [in] exec_queue The queue where the routine should be executed. 343/// \param [in] n The order of the matrices. 344/// \param [in, out] a Array of pointers to matrices. These matrices will be 345/// overwritten by lower triangulars with unit diagonal elements and upper 346/// triangulars. 347/// \param [in] lda The leading dimension of the matrices. 348/// \param [out] ipiv An array stores the pivot indices. If \p ipiv is nullptr, 349/// non-pivoting LU factorization is computed. 350/// \param [out] info An array stores the error information. 351/// \param [in] batch_size The size of the batch. 352template < typename T > 353inline void getrf_batch_wrapper (sycl::queue & exec_queue , int n , T * a [], int lda , 354int * ipiv , int * info , int batch_size ) { 355if ( ipiv == nullptr ) { 356detail:: getrfnp_batch_wrapper ( exec_queue , n , a , lda , info , batch_size ); 357return ; 358} 359using Ty = typename ::dpct::detail::lib_data_traits_t < T > ; 360// Set the info array value to 0 361::dpct::cs:: fill < unsigned char > ( exec_queue , info , 0 , 362sizeof (int) * batch_size ); 363#ifdef DPCT_USM_LEVEL_NONE 364std::int64_t stride_a = n * lda ; 365std::int64_t stride_ipiv = n ; 366std::int64_t scratchpad_size = 367oneapi::mkl::lapack:: getrf_batch_scratchpad_size < Ty > ( 368exec_queue , n , n , lda , stride_a , stride_ipiv , batch_size ); 369 370T * a_buffer_ptr ; 371a_buffer_ptr = (T * )::dpct::cs:: malloc ( stride_a * batch_size * sizeof ( T )); 372 373T ** host_a = (T ** )std:: malloc ( batch_size * sizeof (T * )); 374dpct_memcpy ( host_a , a , batch_size * sizeof (T * )); 375for (std::int64_t i = 0 ; i < batch_size ; ++ i ) 376dpct_memcpy ( a_buffer_ptr + i * stride_a , host_a [ i ], n * lda * sizeof ( T )); 377 378{ 379sycl::buffer < std::int64_t, 1 > ipiv_buf ( 380sycl::range < 1 > (batch_size * stride_ipiv )); 381sycl::buffer < Ty, 1 > scratchpad {sycl:: range < 1 > ( scratchpad_size )}; 382auto a_buffer = get_buffer < Ty > ( a_buffer_ptr ); 383oneapi::mkl::lapack:: getrf_batch ( exec_queue , n , n , a_buffer , lda , stride_a , 384ipiv_buf , stride_ipiv , batch_size , 385scratchpad , scratchpad_size ); 386 387auto to_buffer = get_buffer < int > ( ipiv ); 388exec_queue . submit ([ & ](sycl::handler & cgh ) { 389auto from_acc = ipiv_buf . get_access < sycl::access_mode::read > ( cgh ); 390auto to_acc = to_buffer . get_access < sycl::access_mode::write > ( cgh ); 391cgh . parallel_for < 392::dpct::cs::kernel_name < class getrf_device_int64_to_int, T >> ( 393sycl:: range < 2 > ( batch_size , n ), [ = ](sycl::id < 2 > id ) { 394to_acc [ id . get ( 0 ) * n + id . get ( 1 )] = 395static_cast < int > ( from_acc [ id . get ( 0 ) * stride_ipiv + id . get ( 1 )]); 396}); 397}); 398} 399 400// Copy back to the original buffers 401std::vector < sycl::event > events ; 402for (std::int64_t i = 0 ; i < batch_size ; ++ i ) 403events . push_back (::dpct::cs:: memcpy ( 404exec_queue , host_a [ i ], a_buffer_ptr + i * stride_a , n * lda * sizeof ( T ), 405::dpct::cs::memcpy_direction:: automatic )); 406 407std::vector < void *> ptrs { host_a }; 408std::thread mem_free_thread ( 409[ = ](std::vector < void *> pointers_array , 410std::vector < sycl::event > events_array ) { 411sycl::event:: wait ( events_array ); 412for (auto p : pointers_array ) 413std:: free ( p ); 414}, 415ptrs , events ); 416mem_free_thread . detach (); 417#else 418std::int64_t * m_int64 = new std::int64_t; 419std::int64_t * n_int64 = new std::int64_t; 420std::int64_t * lda_int64 = new std::int64_t; 421std::int64_t * group_sizes = new std::int64_t; 422* m_int64 = n ; 423* n_int64 = n ; 424* lda_int64 = lda ; 425* group_sizes = batch_size ; 426std::int64_t scratchpad_size = 427oneapi::mkl::lapack:: getrf_batch_scratchpad_size < Ty > ( 428exec_queue , m_int64 , n_int64 , lda_int64 , 1 , group_sizes ); 429 430Ty * scratchpad = sycl:: malloc_device < Ty > ( scratchpad_size , exec_queue ); 431std::int64_t * ipiv_int64 = 432sycl:: malloc_device < std::int64_t > ( batch_size * n , exec_queue ); 433std::int64_t ** ipiv_int64_ptr = 434sycl:: malloc_shared < std::int64_t *> ( batch_size , exec_queue ); 435T ** a_shared = sycl:: malloc_shared < T *> ( batch_size , exec_queue ); 436exec_queue . memcpy ( a_shared , a , batch_size * sizeof (T * )). wait (); 437for (std::int64_t i = 0 ; i < batch_size ; ++ i ) 438ipiv_int64_ptr [ i ] = ipiv_int64 + n * i ; 439 440oneapi::mkl::lapack:: getrf_batch ( exec_queue , m_int64 , n_int64 , 441(Ty ** ) a_shared , lda_int64 , ipiv_int64_ptr , 4421 , group_sizes , scratchpad , scratchpad_size ); 443 444sycl::event e = exec_queue . submit ([ & ](sycl::handler & cgh ) { 445cgh . parallel_for < 446::dpct::cs::kernel_name < class getrf_device_int64_to_int, T >> ( 447sycl:: range < 1 > ( batch_size * n ), [ = ](sycl::id < 1 > idx ) { 448ipiv [ idx ] = static_cast < int > ( ipiv_int64 [ idx ]); 449}); 450}); 451 452exec_queue . submit ([ & ](sycl::handler & cgh ) { 453cgh . depends_on ( e ); 454cgh . host_task ([ = ] { 455delete m_int64 ; 456delete n_int64 ; 457delete lda_int64 ; 458delete group_sizes ; 459}); 460}); 461std::vector < void *> ptrs { scratchpad , ipiv_int64 , ipiv_int64_ptr , a_shared }; 462::dpct::cs:: enqueue_free ( ptrs , { e }, exec_queue ); 463#endif 464} 465 466/// Solves a system of linear equations with a batch of LU-factored square 467/// coefficient matrices, with multiple right-hand sides. 468/// \param [in] exec_queue The queue where the routine should be executed. 469/// \param [in] trans Indicates the form of the linear equations. 470/// \param [in] n The order of the matrices. 471/// \param [in] nrhs The number of right hand sides. 472/// \param [in] a Array of pointers to matrices. 473/// \param [in] lda The leading dimension of the matrices in \p a. 474/// \param [in] ipiv An array stores the pivots. 475/// \param [in, out] b Array of pointers to matrices, whose columns are 476/// the right-hand sides for the systems of equations. 477/// \param [in] ldb The leading dimension of the matrices in \p b. 478/// \param [out] info A value stores the error information. 479/// \param [in] batch_size The size of the batch. 480template < typename T > 481inline void getrs_batch_wrapper (sycl::queue & exec_queue , 482oneapi::mkl::transpose trans , int n , int nrhs , 483const T * a [], int lda , const int * ipiv , T * b [], 484int ldb , int * info , int batch_size ) { 485using Ty = typename ::dpct::detail::lib_data_traits_t < T > ; 486// Set the info value to 0 487* info = 0 ; 488#ifdef DPCT_USM_LEVEL_NONE 489std::int64_t stride_a = n * lda ; 490std::int64_t stride_b = nrhs * ldb ; 491std::int64_t stride_ipiv = n ; 492std::int64_t scratchpad_size = 493oneapi::mkl::lapack:: getrs_batch_scratchpad_size < Ty > ( 494exec_queue , trans , n , nrhs , lda , stride_a , stride_ipiv , ldb , stride_b , 495batch_size ); 496 497T * a_buffer_ptr , * b_buffer_ptr ; 498a_buffer_ptr = (T * )::dpct::cs:: malloc ( stride_a * batch_size * sizeof ( T )); 499b_buffer_ptr = (T * )::dpct::cs:: malloc ( stride_b * batch_size * sizeof ( T )); 500 501T ** host_a = (T ** )std:: malloc ( batch_size * sizeof (T * )); 502T ** host_b = (T ** )std:: malloc ( batch_size * sizeof (T * )); 503dpct_memcpy ( host_a , a , batch_size * sizeof (T * )); 504dpct_memcpy ( host_b , b , batch_size * sizeof (T * )); 505for (std::int64_t i = 0 ; i < batch_size ; ++ i ) { 506dpct_memcpy ( a_buffer_ptr + i * stride_a , host_a [ i ], n * lda * sizeof ( T )); 507dpct_memcpy ( b_buffer_ptr + i * stride_b , host_b [ i ], nrhs * ldb * sizeof ( T )); 508} 509 510{ 511auto a_buffer = get_buffer < Ty > ( a_buffer_ptr ); 512auto b_buffer = get_buffer < Ty > ( b_buffer_ptr ); 513sycl::buffer < Ty, 1 > scratchpad {sycl:: range < 1 > ( scratchpad_size )}; 514sycl::buffer < std::int64_t, 1 > ipiv_buf ( 515sycl::range < 1 > (batch_size * stride_ipiv )); 516auto from_buf = get_buffer < int > ( ipiv ); 517exec_queue . submit ([ & ](sycl::handler & cgh ) { 518auto from_acc = from_buf . get_access < sycl::access_mode::read > ( cgh ); 519auto to_acc = ipiv_buf . get_access < sycl::access_mode::write > ( cgh ); 520cgh . parallel_for < 521::dpct::cs::kernel_name < class getrs_device_int64_to_int, T >> ( 522sycl:: range < 2 > ( batch_size , n ), [ = ](sycl::id < 2 > id ) { 523to_acc [ id . get ( 0 ) * stride_ipiv + id . get ( 1 )] = 524static_cast < std::int64_t > ( from_acc [ id . get ( 0 ) * n + id . get ( 1 )]); 525}); 526}); 527 528oneapi::mkl::lapack:: getrs_batch ( exec_queue , trans , n , nrhs , a_buffer , lda , 529stride_a , ipiv_buf , stride_ipiv , b_buffer , 530ldb , stride_b , batch_size , scratchpad , 531scratchpad_size ); 532} 533 534// Copy back to the original buffers 535std::vector < sycl::event > events ; 536for (std::int64_t i = 0 ; i < batch_size ; ++ i ) 537events . push_back (::dpct::cs:: memcpy ( 538exec_queue , host_b [ i ], b_buffer_ptr + i * stride_b , 539nrhs * ldb * sizeof ( T ), ::dpct::cs::memcpy_direction:: automatic )); 540std::vector < void *> ptrs { host_a , host_b }; 541std::thread mem_free_thread ( 542[ = ](std::vector < void *> pointers_array , 543std::vector < sycl::event > events_array ) { 544sycl::event:: wait ( events_array ); 545for (auto p : pointers_array ) 546std:: free ( p ); 547}, 548ptrs , events ); 549mem_free_thread . detach (); 550#else 551std::int64_t * n_int64 = new std::int64_t; 552std::int64_t * nrhs_int64 = new std::int64_t; 553std::int64_t * lda_int64 = new std::int64_t; 554std::int64_t * ldb_int64 = new std::int64_t; 555std::int64_t * group_sizes = new std::int64_t; 556oneapi::mkl::transpose * trans_array = new oneapi::mkl::transpose; 557* n_int64 = n ; 558* nrhs_int64 = nrhs ; 559* lda_int64 = lda ; 560* ldb_int64 = ldb ; 561* group_sizes = batch_size ; 562* trans_array = trans ; 563std::int64_t scratchpad_size = 564oneapi::mkl::lapack:: getrs_batch_scratchpad_size < Ty > ( 565exec_queue , trans_array , n_int64 , nrhs_int64 , lda_int64 , ldb_int64 , 1 , 566group_sizes ); 567 568Ty * scratchpad = sycl:: malloc_device < Ty > ( scratchpad_size , exec_queue ); 569std::int64_t * ipiv_int64 = 570sycl:: malloc_device < std::int64_t > ( batch_size * n , exec_queue ); 571std::int64_t ** ipiv_int64_ptr = 572sycl:: malloc_shared < std::int64_t *> ( batch_size , exec_queue ); 573T ** a_shared = sycl:: malloc_shared < T *> ( batch_size , exec_queue ); 574T ** b_shared = sycl:: malloc_shared < T *> ( batch_size , exec_queue ); 575exec_queue . memcpy ( a_shared , a , batch_size * sizeof (T * )); 576exec_queue . memcpy ( b_shared , b , batch_size * sizeof (T * )); 577 578exec_queue 579. submit ([ & ](sycl::handler & cgh ) { 580cgh . parallel_for < 581::dpct::cs::kernel_name < class getrs_device_int64_to_int, T >> ( 582sycl:: range < 1 > ( batch_size * n ), [ = ](sycl::id < 1 > idx ) { 583ipiv_int64 [ idx ] = static_cast < std::int64_t > ( ipiv [ idx ]); 584}); 585}) 586. wait (); 587 588for (std::int64_t i = 0 ; i < batch_size ; ++ i ) 589ipiv_int64_ptr [ i ] = ipiv_int64 + n * i ; 590 591sycl::event e = oneapi::mkl::lapack:: getrs_batch ( 592exec_queue , trans_array , n_int64 , nrhs_int64 , (Ty ** ) a_shared , lda_int64 , 593ipiv_int64_ptr , (Ty ** ) b_shared , ldb_int64 , 1 , group_sizes , scratchpad , 594scratchpad_size ); 595 596exec_queue . submit ([ & ](sycl::handler & cgh ) { 597cgh . depends_on ( e ); 598cgh . host_task ([ = ] { 599delete n_int64 ; 600delete nrhs_int64 ; 601delete lda_int64 ; 602delete ldb_int64 ; 603delete group_sizes ; 604delete trans_array ; 605}); 606}); 607std::vector < void *> ptrs { scratchpad , ipiv_int64_ptr , ipiv_int64 , a_shared , 608b_shared }; 609::dpct::cs:: enqueue_free ( ptrs , { e }, exec_queue ); 610#endif 611} 612 613/// Computes the inverses of a batch of LU-factored matrices. 614/// \param [in] exec_queue The queue where the routine should be executed. 615/// \param [in] n The order of the matrices. 616/// \param [in] a Array of pointers to matrices. 617/// \param [in] lda The leading dimension of the matrices in \p a. 618/// \param [in] ipiv An array stores the pivots. 619/// \param [out] b Array of pointers to inverse matrices. 620/// \param [in] ldb The leading dimension of the matrices in \p b. 621/// \param [out] info An array stores the error information. 622/// \param [in] batch_size The size of the batch. 623template < typename T > 624inline void getri_batch_wrapper (sycl::queue & exec_queue , int n , const T * a [], 625int lda , int * ipiv , T * b [], int ldb , int * info , 626int batch_size ) { 627using Ty = typename ::dpct::detail::lib_data_traits_t < T > ; 628// Set the info array value to 0 629::dpct::cs:: fill < unsigned char > ( exec_queue , info , 0 , 630sizeof (int) * batch_size ); 631#ifdef DPCT_USM_LEVEL_NONE 632std::int64_t stride_b = n * ldb ; 633std::int64_t stride_ipiv = n ; 634std::int64_t scratchpad_size = 635oneapi::mkl::lapack:: getri_batch_scratchpad_size < Ty > ( 636exec_queue , n , ldb , stride_b , stride_ipiv , batch_size ); 637 638T * b_buffer_ptr ; 639b_buffer_ptr = (T * )::dpct::cs:: malloc ( stride_b * batch_size * sizeof ( T )); 640 641T ** host_a = (T ** )std:: malloc ( batch_size * sizeof (T * )); 642T ** host_b = (T ** )std:: malloc ( batch_size * sizeof (T * )); 643dpct_memcpy ( host_a , a , batch_size * sizeof (T * )); 644dpct_memcpy ( host_b , b , batch_size * sizeof (T * )); 645 646for (std::int64_t i = 0 ; i < batch_size ; ++ i ) { 647// Need to create a copy of input matrices "a" to keep them unchanged. 648// Matrices "b" (copy of matrices "a") will be used as input and output 649// parameter in oneapi::mkl::lapack::getri_batch call. 650blas:: matrix_mem_copy ( b_buffer_ptr + i * stride_b , host_a [ i ], ldb , lda , n , 651n , sizeof ( T ), dpct:: device_to_device , exec_queue ); 652} 653 654{ 655auto b_buffer = get_buffer < Ty > ( b_buffer_ptr ); 656sycl::buffer < Ty, 1 > scratchpad {sycl:: range < 1 > ( scratchpad_size )}; 657sycl::buffer < std::int64_t, 1 > ipiv_buf ( 658sycl::range < 1 > (batch_size * stride_ipiv )); 659auto from_buf = get_buffer < int > ( ipiv ); 660exec_queue . submit ([ & ](sycl::handler & cgh ) { 661auto from_acc = from_buf . get_access < sycl::access_mode::read > ( cgh ); 662auto to_acc = ipiv_buf . get_access < sycl::access_mode::write > ( cgh ); 663cgh . parallel_for < 664::dpct::cs::kernel_name < class getri_device_int64_to_int, T >> ( 665sycl:: range < 2 > ( batch_size , n ), [ = ](sycl::id < 2 > id ) { 666to_acc [ id . get ( 0 ) * stride_ipiv + id . get ( 1 )] = 667static_cast < std::int64_t > ( from_acc [ id . get ( 0 ) * n + id . get ( 1 )]); 668}); 669}); 670 671oneapi::mkl::lapack:: getri_batch ( exec_queue , n , b_buffer , ldb , stride_b , 672ipiv_buf , stride_ipiv , batch_size , 673scratchpad , scratchpad_size ); 674} 675 676// Copy back to the original buffers 677std::vector < sycl::event > events ; 678for (std::int64_t i = 0 ; i < batch_size ; ++ i ) 679events . push_back (::dpct::cs:: memcpy ( 680exec_queue , host_b [ i ], b_buffer_ptr + i * stride_b , n * ldb * sizeof ( T ), 681::dpct::cs::memcpy_direction:: automatic )); 682std::vector < void *> ptrs { host_a , host_b }; 683std::thread mem_free_thread ( 684[ = ](std::vector < void *> pointers_array , 685std::vector < sycl::event > events_array ) { 686sycl::event:: wait ( events_array ); 687for (auto p : pointers_array ) 688std:: free ( p ); 689}, 690ptrs , events ); 691mem_free_thread . detach (); 692#else 693std::int64_t * n_int64 = new std::int64_t; 694std::int64_t * ldb_int64 = new std::int64_t; 695std::int64_t * group_sizes = new std::int64_t; 696* n_int64 = n ; 697* ldb_int64 = ldb ; 698* group_sizes = batch_size ; 699std::int64_t scratchpad_size = 700oneapi::mkl::lapack:: getri_batch_scratchpad_size < Ty > ( 701exec_queue , n_int64 , ldb_int64 , 1 , group_sizes ); 702 703Ty * scratchpad = sycl:: malloc_device < Ty > ( scratchpad_size , exec_queue ); 704std::int64_t * ipiv_int64 = 705sycl:: malloc_device < std::int64_t > ( batch_size * n , exec_queue ); 706std::int64_t ** ipiv_int64_ptr = 707sycl:: malloc_shared < std::int64_t *> ( batch_size , exec_queue ); 708 709exec_queue . submit ([ & ](sycl::handler & cgh ) { 710cgh . parallel_for < 711::dpct::cs::kernel_name < class getri_device_int64_to_int, T >> ( 712sycl:: range < 1 > ( batch_size * n ), [ = ](sycl::id < 1 > idx ) { 713ipiv_int64 [ idx ] = static_cast < std::int64_t > ( ipiv [ idx ]); 714}); 715}); 716 717T ** a_shared = sycl:: malloc_shared < T *> ( batch_size , exec_queue ); 718T ** b_shared = sycl:: malloc_shared < T *> ( batch_size , exec_queue ); 719exec_queue . memcpy ( a_shared , a , batch_size * sizeof (T * )); 720exec_queue . memcpy ( b_shared , b , batch_size * sizeof (T * )). wait (); 721for (std::int64_t i = 0 ; i < batch_size ; ++ i ) { 722ipiv_int64_ptr [ i ] = ipiv_int64 + n * i ; 723// Need to create a copy of input matrices "a" to keep them unchanged. 724// Matrices "b" (copy of matrices "a") will be used as input and output 725// parameter in oneapi::mkl::lapack::getri_batch call. 726blas:: matrix_mem_copy ( b_shared [ i ], a_shared [ i ], ldb , lda , n , n , sizeof ( T ), 727::dpct::cs::memcpy_direction:: device_to_device , 728exec_queue ); 729} 730 731sycl::event e = oneapi::mkl::lapack:: getri_batch ( 732exec_queue , n_int64 , (Ty ** ) b_shared , ldb_int64 , ipiv_int64_ptr , 1 , 733group_sizes , scratchpad , scratchpad_size ); 734 735exec_queue . submit ([ & ](sycl::handler & cgh ) { 736cgh . depends_on ( e ); 737cgh . host_task ([ = ] { 738delete n_int64 ; 739delete ldb_int64 ; 740delete group_sizes ; 741}); 742}); 743std::vector < void *> ptrs { scratchpad , ipiv_int64_ptr , ipiv_int64 , a_shared , 744b_shared }; 745::dpct::cs:: enqueue_free ( ptrs , { e }, exec_queue ); 746#endif 747} 748 749/// Computes the QR factorizations of a batch of general matrices. 750/// \param [in] exec_queue The queue where the routine should be executed. 751/// \param [in] m The number of rows in the matrices. 752/// \param [in] n The number of columns in the matrices. 753/// \param [in, out] a Array of pointers to matrices. These 754/// matrices will be overwritten by the factorization data. 755/// \param [in] lda The leading dimension of the matrices in \p a. 756/// \param [out] tau An array stores the scalars. 757/// \param [out] info A value stores the error information. 758/// \param [in] batch_size The size of the batch. 759template < typename T > 760inline void geqrf_batch_wrapper (sycl::queue exec_queue , int m , int n , T * a [], 761int lda , T * tau [], int * info , int batch_size ) { 762using Ty = typename ::dpct::detail::lib_data_traits_t < T > ; 763// Set the info value to 0 764* info = 0 ; 765#ifdef DPCT_USM_LEVEL_NONE 766std::int64_t stride_a = n * lda ; 767std::int64_t stride_tau = (std:: max )( 1 , (std:: min )( m , n )); 768std::int64_t scratchpad_size = 769oneapi::mkl::lapack:: geqrf_batch_scratchpad_size < Ty > ( 770exec_queue , m , n , lda , stride_a , stride_tau , batch_size ); 771 772T * a_buffer_ptr , * tau_buffer_ptr ; 773a_buffer_ptr = (T * )::dpct::cs:: malloc ( stride_a * batch_size * sizeof ( T )); 774tau_buffer_ptr = (T * )::dpct::cs:: malloc ( stride_tau * batch_size * sizeof ( T )); 775 776T ** host_a = (T ** )std:: malloc ( batch_size * sizeof (T * )); 777T ** host_tau = (T ** )std:: malloc ( batch_size * sizeof (T * )); 778dpct_memcpy ( host_a , a , batch_size * sizeof (T * )); 779dpct_memcpy ( host_tau , tau , batch_size * sizeof (T * )); 780 781for (std::int64_t i = 0 ; i < batch_size ; ++ i ) 782dpct_memcpy ( a_buffer_ptr + i * stride_a , host_a [ i ], n * lda * sizeof ( T )); 783{ 784auto a_buffer = get_buffer < Ty > ( a_buffer_ptr ); 785auto tau_buffer = get_buffer < Ty > ( tau_buffer_ptr ); 786sycl::buffer < Ty, 1 > scratchpad {sycl:: range < 1 > ( scratchpad_size )}; 787oneapi::mkl::lapack:: geqrf_batch ( exec_queue , m , n , a_buffer , lda , stride_a , 788tau_buffer , stride_tau , batch_size , 789scratchpad , scratchpad_size ); 790} 791 792// Copy back to the original buffers 793std::vector < sycl::event > events_a ; 794std::vector < sycl::event > events_tau ; 795for (std::int64_t i = 0 ; i < batch_size ; ++ i ) { 796events_a . push_back (::dpct::cs:: memcpy ( 797exec_queue , host_a [ i ], a_buffer_ptr + i * stride_a , n * lda * sizeof ( T ), 798::dpct::cs::memcpy_direction:: automatic )); 799events_tau . push_back (::dpct::cs:: memcpy ( 800exec_queue , host_tau [ i ], tau_buffer_ptr + i * stride_tau , 801(std:: max )( 1 , (std:: min )( m , n )) * sizeof ( T ), 802::dpct::cs::memcpy_direction:: automatic )); 803} 804std::vector < void *> ptr_a { host_a }; 805std::vector < void *> ptr_tau { host_tau }; 806std::thread mem_free_thread_a ( 807[ = ](std::vector < void *> pointers_array , 808std::vector < sycl::event > events_array ) { 809sycl::event:: wait ( events_array ); 810for (auto p : pointers_array ) 811std:: free ( p ); 812}, 813ptr_a , events_a ); 814std::thread mem_free_thread_tau ( 815[ = ](std::vector < void *> pointers_array , 816std::vector < sycl::event > events_array ) { 817sycl::event:: wait ( events_array ); 818for (auto p : pointers_array ) 819std:: free ( p ); 820}, 821ptr_tau , events_tau ); 822mem_free_thread_a . detach (); 823mem_free_thread_tau . detach (); 824#else 825std::int64_t * m_int64 = new std::int64_t; 826std::int64_t * n_int64 = new std::int64_t; 827std::int64_t * lda_int64 = new std::int64_t; 828std::int64_t * group_sizes = new std::int64_t; 829* m_int64 = n ; 830* n_int64 = n ; 831* lda_int64 = lda ; 832* group_sizes = batch_size ; 833std::int64_t scratchpad_size = 834oneapi::mkl::lapack:: geqrf_batch_scratchpad_size < Ty > ( 835exec_queue , m_int64 , n_int64 , lda_int64 , 1 , group_sizes ); 836 837Ty * scratchpad = sycl:: malloc_device < Ty > ( scratchpad_size , exec_queue ); 838T ** a_shared = sycl:: malloc_shared < T *> ( batch_size , exec_queue ); 839T ** tau_shared = sycl:: malloc_shared < T *> ( batch_size , exec_queue ); 840exec_queue . memcpy ( a_shared , a , batch_size * sizeof (T * )); 841exec_queue . memcpy ( tau_shared , tau , batch_size * sizeof (T * )). wait (); 842 843sycl::event e = oneapi::mkl::lapack:: geqrf_batch ( 844exec_queue , m_int64 , n_int64 , (Ty ** ) a_shared , lda_int64 , 845(Ty ** ) tau_shared , 1 , group_sizes , scratchpad , scratchpad_size ); 846 847exec_queue . submit ([ & ](sycl::handler & cgh ) { 848cgh . depends_on ( e ); 849cgh . host_task ([ = ] { 850delete m_int64 ; 851delete n_int64 ; 852delete lda_int64 ; 853delete group_sizes ; 854}); 855}); 856std::vector < void *> ptrs { scratchpad , a_shared , tau_shared }; 857::dpct::cs:: enqueue_free ( ptrs , { e }, exec_queue ); 858#endif 859} 860 861namespace blas { 862#ifdef __INTEL_MKL__ 863template < typename T > 864inline oneapi::mkl::blas::compute_mode 865deduce_compute_mode (std::optional < compute_type > ct , math_mode mm ) { 866using Ty = typename ::dpct::detail::lib_data_traits_t < T > ; 867if ( ct ) { 868switch ( ct . value ()) { 869case compute_type:: f16_standard : 870case compute_type:: f32_standard : 871case compute_type:: f64_standard : 872case compute_type:: i32_standard : 873return oneapi::mkl::blas::compute_mode:: standard ; 874case compute_type:: f32 : 875if constexpr (std:: is_same_v < Ty, std::complex < float >> || 876std:: is_same_v < Ty, std::complex < double >> ) 877return oneapi::mkl::blas::compute_mode:: complex_3m ; 878break ; 879case compute_type:: f32_fast_bf16 : 880return oneapi::mkl::blas::compute_mode:: float_to_bf16 ; 881case compute_type:: f32_fast_tf32 : 882return oneapi::mkl::blas::compute_mode:: float_to_tf32 ; 883default : 884[[ fallthrough ]]; 885} 886} 887if ( mm == math_mode:: mm_tf32 ) 888return oneapi::mkl::blas::compute_mode:: float_to_tf32 ; 889return oneapi::mkl::blas::compute_mode:: unset ; 890} 891 892inline oneapi::mkl::blas::compute_mode 893deduce_compute_mode (std::optional < compute_type > ct , math_mode mm , 894bool is_complex ) { 895if ( is_complex ) 896return deduce_compute_mode < std::complex < float >> ( ct , mm ); 897return deduce_compute_mode < float > ( ct , mm ); 898} 899#endif 900 901/// Computes matrix-matrix product with general matrices. 902/// \param [in] desc_ptr Descriptor. 903/// \param [in] a_trans Specifies the operation applied to A. 904/// \param [in] b_trans Specifies the operation applied to B. 905/// \param [in] m Specifies the number of rows of the matrix op(A) and of the matrix C. 906/// \param [in] n Specifies the number of columns of the matrix op(B) and of the matrix C. 907/// \param [in] k Specifies the number of columns of the matrix op(A) and the number of rows of the matrix op(B). 908/// \param [in] alpha Scaling factor for the matrix-matrix product. 909/// \param [in] a Input matrix A. 910/// \param [in] a_type Data type of the matrix A. 911/// \param [in] lda Leading dimension of A. 912/// \param [in] b Input matrix B. 913/// \param [in] b_type Data type of the matrix B. 914/// \param [in] ldb Leading dimension of B. 915/// \param [in] beta Scaling factor for matrix C. 916/// \param [in, out] c Input/Output matrix C. 917/// \param [in] c_type Data type of the matrix C. 918/// \param [in] ldc Leading dimension of C. 919/// \param [in] ct Compute type. 920inline void gemm (descriptor_ptr desc_ptr , oneapi::mkl::transpose a_trans , 921oneapi::mkl::transpose b_trans , std::int64_t m , std::int64_t n , 922std::int64_t k , const void * alpha , const void * a , 923library_data_t a_type , std::int64_t lda , const void * b , 924library_data_t b_type , std::int64_t ldb , const void * beta , 925void * c , library_data_t c_type , std::int64_t ldc , 926std::variant < compute_type, library_data_t > ct ) { 927#ifndef __INTEL_MKL__ 928throw std:: runtime_error ( "The oneAPI Math Kernel Library (oneMKL) Interfaces " 929"Project does not support this API." ); 930#else 931sycl::queue q = desc_ptr -> get_queue (); 932oneapi::mkl::blas::compute_mode cm = oneapi::mkl::blas::compute_mode:: unset ; 933library_data_t scaling_type ; 934if (auto ct_p = std:: get_if < compute_type > ( & ct )) { 935cm = deduce_compute_mode ( * ct_p , desc_ptr -> get_math_mode (), 936a_type == library_data_t:: complex_float || 937a_type == library_data_t:: complex_double ); 938scaling_type = detail:: compute_type_to_library_data_t ( * ct_p ); 939} else { 940cm = deduce_compute_mode (std:: nullopt , desc_ptr -> get_math_mode (), 941a_type == library_data_t:: complex_float || 942a_type == library_data_t:: complex_double ); 943scaling_type = std:: get < library_data_t > ( ct ); 944} 945 946if ( scaling_type == library_data_t:: real_float && 947c_type == library_data_t:: complex_float ) { 948scaling_type = library_data_t:: complex_float ; 949} else if ( scaling_type == library_data_t:: real_double && 950c_type == library_data_t:: complex_double ) { 951scaling_type = library_data_t:: complex_double ; 952} 953 954std::uint64_t key = dpct::detail:: get_type_combination_id ( 955a_type , b_type , c_type , scaling_type ); 956switch ( key ) { 957case dpct::detail:: get_type_combination_id ( 958library_data_t:: real_float , library_data_t:: real_float , 959library_data_t:: real_float , library_data_t:: real_float ): { 960dpct::detail:: gemm_impl < float, float, float, float > ( 961q , a_trans , b_trans , m , n , k , alpha , a , lda , b , ldb , beta , c , ldc , cm ); 962break ; 963} 964case dpct::detail:: get_type_combination_id ( 965library_data_t:: real_double , library_data_t:: real_double , 966library_data_t:: real_double , library_data_t:: real_double ): { 967dpct::detail:: gemm_impl < double, double, double, double > ( 968q , a_trans , b_trans , m , n , k , alpha , a , lda , b , ldb , beta , c , ldc , cm ); 969break ; 970} 971case dpct::detail:: get_type_combination_id ( 972library_data_t:: complex_float , library_data_t:: complex_float , 973library_data_t:: complex_float , library_data_t:: complex_float ): { 974dpct::detail:: gemm_impl < std::complex < float > , std::complex < float > , 975std::complex < float > , std::complex < float >> ( 976q , a_trans , b_trans , m , n , k , alpha , a , lda , b , ldb , beta , c , ldc , cm ); 977break ; 978} 979case dpct::detail:: get_type_combination_id ( 980library_data_t:: complex_double , library_data_t:: complex_double , 981library_data_t:: complex_double , library_data_t:: complex_double ): { 982dpct::detail:: gemm_impl < std::complex < double > , std::complex < double > , 983std::complex < double > , std::complex < double >> ( 984q , a_trans , b_trans , m , n , k , alpha , a , lda , b , ldb , beta , c , ldc , cm ); 985break ; 986} 987case dpct::detail:: get_type_combination_id ( 988library_data_t:: real_half , library_data_t:: real_half , 989library_data_t:: real_half , library_data_t:: real_half ): { 990dpct::detail:: gemm_impl < sycl::half, sycl::half, sycl::half, sycl::half > ( 991q , a_trans , b_trans , m , n , k , alpha , a , lda , b , ldb , beta , c , ldc , cm ); 992break ; 993} 994case dpct::detail:: get_type_combination_id ( 995library_data_t:: real_bfloat16 , library_data_t:: real_bfloat16 , 996library_data_t:: real_float , library_data_t:: real_float ): { 997dpct::detail:: gemm_impl < oneapi::mkl::bfloat16, oneapi::mkl::bfloat16, float, 998float > ( q , a_trans , b_trans , m , n , k , alpha , a , lda , 999b , ldb , beta , c , ldc , cm ); 1000break ; 1001} 1002case dpct::detail:: get_type_combination_id ( 1003library_data_t:: real_half , library_data_t:: real_half , 1004library_data_t:: real_float , library_data_t:: real_float ): { 1005dpct::detail:: gemm_impl < sycl::half, sycl::half, float, float > ( 1006q , a_trans , b_trans , m , n , k , alpha , a , lda , b , ldb , beta , c , ldc , cm ); 1007break ; 1008} 1009case dpct::detail:: get_type_combination_id ( 1010library_data_t:: real_half , library_data_t:: real_half , 1011library_data_t:: real_half , library_data_t:: real_float ): { 1012float alpha_value = 1013dpct:: get_value ( reinterpret_cast < const float *> ( alpha ), q ); 1014float beta_value = 1015dpct:: get_value ( reinterpret_cast < const float *> ( beta ), q ); 1016sycl::half alpha_half (alpha_value); 1017sycl::half beta_half (beta_value); 1018dpct::detail:: gemm_impl < sycl::half, sycl::half, sycl::half, sycl::half > ( 1019q , a_trans , b_trans , m , n , k , & alpha_half , a , lda , b , ldb , & beta_half , 1020c , ldc , cm ); 1021break ; 1022} 1023case dpct::detail:: get_type_combination_id ( 1024library_data_t:: real_int8 , library_data_t:: real_int8 , 1025library_data_t:: real_float , library_data_t:: real_float ): { 1026dpct::detail:: gemm_impl < std::int8_t, std::int8_t, float, float > ( 1027q , a_trans , b_trans , m , n , k , alpha , a , lda , b , ldb , beta , c , ldc , cm ); 1028break ; 1029} 1030case dpct::detail:: get_type_combination_id ( 1031library_data_t:: real_bfloat16 , library_data_t:: real_bfloat16 , 1032library_data_t:: real_bfloat16 , library_data_t:: real_float ): { 1033dpct::detail:: gemm_impl < oneapi::mkl::bfloat16, oneapi::mkl::bfloat16, 1034oneapi::mkl::bfloat16, float > ( 1035q , a_trans , b_trans , m , n , k , alpha , a , lda , b , ldb , beta , c , ldc , cm ); 1036break ; 1037} 1038case dpct::detail:: get_type_combination_id ( 1039library_data_t:: real_int8 , library_data_t:: real_int8 , 1040library_data_t:: real_int32 , library_data_t:: real_int32 ): { 1041float alpha_float = 1042dpct:: get_value ( reinterpret_cast < const std::int32_t *> ( alpha ), q ); 1043float beta_float = 1044dpct:: get_value ( reinterpret_cast < const std::int32_t *> ( beta ), q ); 1045dpct::detail:: gemm_impl < std::int8_t, std::int8_t, std::int32_t, float > ( 1046q , a_trans , b_trans , m , n , k , & alpha_float , a , lda , b , ldb , & beta_float , 1047c , ldc , cm ); 1048break ; 1049} 1050default : 1051throw std:: runtime_error ( "the combination of data type is unsupported" ); 1052} 1053#endif 1054} 1055 1056/// Computes a batch of matrix-matrix product with general matrices. 1057/// \param [in] desc_ptr Descriptor. 1058/// \param [in] a_trans Specifies the operation applied to A. 1059/// \param [in] b_trans Specifies the operation applied to B. 1060/// \param [in] m Specifies the number of rows of the matrix op(A) and of the matrix C. 1061/// \param [in] n Specifies the number of columns of the matrix op(B) and of the matrix C. 1062/// \param [in] k Specifies the number of columns of the matrix op(A) and the number of rows of the matrix op(B). 1063/// \param [in] alpha Scaling factor for the matrix-matrix product. 1064/// \param [in] a Input matrix A. 1065/// \param [in] a_type Data type of the matrix A. 1066/// \param [in] lda Leading dimension of A. 1067/// \param [in] b Input matrix B. 1068/// \param [in] b_type Data type of the matrix B. 1069/// \param [in] ldb Leading dimension of B. 1070/// \param [in] beta Scaling factor for matrix C. 1071/// \param [in, out] c Input/Output matrix C. 1072/// \param [in] c_type Data type of the matrix C. 1073/// \param [in] ldc Leading dimension of C. 1074/// \param [in] batch_size Specifies the number of matrix multiply operations to perform. 1075/// \param [in] scaling_type Data type of the scaling factors. 1076/// \param [in] ct Compute type. 1077inline void gemm_batch (descriptor_ptr desc_ptr , oneapi::mkl::transpose a_trans , 1078oneapi::mkl::transpose b_trans , std::int64_t m , 1079std::int64_t n , std::int64_t k , const void * alpha , 1080const void * a [], library_data_t a_type , std::int64_t lda , 1081const void * b [], library_data_t b_type , std::int64_t ldb , 1082const void * beta , void * c [], library_data_t c_type , 1083std::int64_t ldc , std::int64_t batch_size , 1084std::variant < compute_type, library_data_t > ct ) { 1085#ifdef DPCT_USM_LEVEL_NONE 1086throw std:: runtime_error ( "this API is unsupported when USM level is none" ); 1087#else 1088sycl::queue q = desc_ptr -> get_queue (); 1089#ifdef __INTEL_MKL__ 1090oneapi::mkl::blas::compute_mode cm = oneapi::mkl::blas::compute_mode:: unset ; 1091#endif 1092library_data_t scaling_type ; 1093if (auto ct_p = std:: get_if < compute_type > ( & ct )) { 1094#ifdef __INTEL_MKL__ 1095cm = deduce_compute_mode ( * ct_p , desc_ptr -> get_math_mode (), 1096a_type == library_data_t:: complex_float || 1097a_type == library_data_t:: complex_double ); 1098#endif 1099scaling_type = detail:: compute_type_to_library_data_t ( * ct_p ); 1100} else { 1101#ifdef __INTEL_MKL__ 1102cm = deduce_compute_mode (std:: nullopt , desc_ptr -> get_math_mode (), 1103a_type == library_data_t:: complex_float || 1104a_type == library_data_t:: complex_double ); 1105#endif 1106scaling_type = std:: get < library_data_t > ( ct ); 1107} 1108 1109if ( scaling_type == library_data_t:: real_float && 1110c_type == library_data_t:: complex_float ) { 1111scaling_type = library_data_t:: complex_float ; 1112} else if ( scaling_type == library_data_t:: real_double && 1113c_type == library_data_t:: complex_double ) { 1114scaling_type = library_data_t:: complex_double ; 1115} 1116 1117std::uint64_t key = dpct::detail:: get_type_combination_id ( 1118a_type , b_type , c_type , scaling_type ); 1119switch ( key ) { 1120case dpct::detail:: get_type_combination_id ( 1121library_data_t:: real_float , library_data_t:: real_float , 1122library_data_t:: real_float , library_data_t:: real_float ): { 1123dpct::detail:: gemm_batch_impl < float, float, float, float > ( 1124q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc, 1125batch_size DPCT_COMPUTE_MODE_ARG ); 1126break ; 1127} 1128case dpct::detail:: get_type_combination_id ( 1129library_data_t:: real_double , library_data_t:: real_double , 1130library_data_t:: real_double , library_data_t:: real_double ): { 1131dpct::detail:: gemm_batch_impl < double, double, double, double > ( 1132q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc, 1133batch_size DPCT_COMPUTE_MODE_ARG ); 1134break ; 1135} 1136case dpct::detail:: get_type_combination_id ( 1137library_data_t:: complex_float , library_data_t:: complex_float , 1138library_data_t:: complex_float , library_data_t:: complex_float ): { 1139dpct::detail:: gemm_batch_impl < std::complex < float > , std::complex < float > , 1140std::complex < float > , std::complex < float >> ( 1141q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc, 1142batch_size DPCT_COMPUTE_MODE_ARG ); 1143break ; 1144} 1145case dpct::detail:: get_type_combination_id ( 1146library_data_t:: complex_double , library_data_t:: complex_double , 1147library_data_t:: complex_double , library_data_t:: complex_double ): { 1148dpct::detail:: gemm_batch_impl < std::complex < double > , std::complex < double > , 1149std::complex < double > , std::complex < double >> ( 1150q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc, 1151batch_size DPCT_COMPUTE_MODE_ARG ); 1152break ; 1153} 1154case dpct::detail:: get_type_combination_id ( 1155library_data_t:: real_half , library_data_t:: real_half , 1156library_data_t:: real_half , library_data_t:: real_half ): { 1157dpct::detail:: gemm_batch_impl < sycl::half, sycl::half, sycl::half, 1158sycl::half > (q, a_trans, b_trans, m, n, k, 1159alpha, a, lda, b, ldb, beta, c, 1160ldc, batch_size DPCT_COMPUTE_MODE_ARG ); 1161break ; 1162} 1163#ifdef __INTEL_MKL__ 1164case dpct::detail:: get_type_combination_id ( 1165library_data_t:: real_bfloat16 , library_data_t:: real_bfloat16 , 1166library_data_t:: real_bfloat16 , library_data_t:: real_float ): { 1167dpct::detail:: gemm_batch_impl < oneapi::mkl::bfloat16, oneapi::mkl::bfloat16, 1168oneapi::mkl::bfloat16, float > ( 1169q , a_trans , b_trans , m , n , k , alpha , a , lda , b , ldb , beta , c , ldc , 1170batch_size , cm ); 1171break ; 1172} 1173case dpct::detail:: get_type_combination_id ( 1174library_data_t:: real_bfloat16 , library_data_t:: real_bfloat16 , 1175library_data_t:: real_float , library_data_t:: real_float ): { 1176dpct::detail:: gemm_batch_impl < oneapi::mkl::bfloat16, oneapi::mkl::bfloat16, 1177float, float > ( q , a_trans , b_trans , m , n , k , 1178alpha , a , lda , b , ldb , beta , c , 1179ldc , batch_size , cm ); 1180break ; 1181} 1182#endif 1183case dpct::detail:: get_type_combination_id ( 1184library_data_t:: real_int8 , library_data_t:: real_int8 , 1185library_data_t:: real_int32 , library_data_t:: real_int32 ): { 1186float alpha_float = 1187dpct:: get_value ( reinterpret_cast < const std::int32_t *> ( alpha ), q ); 1188float beta_float = 1189dpct:: get_value ( reinterpret_cast < const std::int32_t *> ( beta ), q ); 1190dpct::detail:: gemm_batch_impl < std::int8_t, std::int8_t, std::int32_t, 1191float > ( 1192q , a_trans , b_trans , m , n , k , & alpha_float , a , lda , b , ldb , & beta_float , 1193c , ldc , batch_size DPCT_COMPUTE_MODE_ARG ); 1194break ; 1195} 1196case dpct::detail:: get_type_combination_id ( 1197library_data_t:: real_int8 , library_data_t:: real_int8 , 1198library_data_t:: real_float , library_data_t:: real_float ): { 1199dpct::detail:: gemm_batch_impl < std::int8_t, std::int8_t, float, float > ( 1200q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc, 1201batch_size DPCT_COMPUTE_MODE_ARG ); 1202break ; 1203} 1204case dpct::detail:: get_type_combination_id ( 1205library_data_t:: real_half , library_data_t:: real_half , 1206library_data_t:: real_float , library_data_t:: real_float ): { 1207dpct::detail:: gemm_batch_impl < sycl::half, sycl::half, float, float > ( 1208q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc, 1209batch_size DPCT_COMPUTE_MODE_ARG ); 1210break ; 1211} 1212case dpct::detail:: get_type_combination_id ( 1213library_data_t:: real_half , library_data_t:: real_half , 1214library_data_t:: real_half , library_data_t:: real_float ): { 1215float alpha_value = 1216dpct:: get_value ( reinterpret_cast < const float *> ( alpha ), q ); 1217float beta_value = 1218dpct:: get_value ( reinterpret_cast < const float *> ( beta ), q ); 1219sycl::half alpha_half (alpha_value); 1220sycl::half beta_half (beta_value); 1221dpct::detail:: gemm_batch_impl < sycl::half, sycl::half, sycl::half, 1222sycl::half > ( 1223q , a_trans , b_trans , m , n , k , & alpha_half , a , lda , b , ldb , & beta_half , 1224c , ldc , batch_size DPCT_COMPUTE_MODE_ARG ); 1225break ; 1226} 1227default : 1228throw std:: runtime_error ( "the combination of data type is unsupported" ); 1229} 1230#endif 1231} 1232 1233/// Computes a batch of matrix-matrix product with general matrices. 1234/// \param [in] desc_ptr Descriptor. 1235/// \param [in] a_trans Specifies the operation applied to A. 1236/// \param [in] b_trans Specifies the operation applied to B. 1237/// \param [in] m Specifies the number of rows of the matrix op(A) and of the matrix C. 1238/// \param [in] n Specifies the number of columns of the matrix op(B) and of the matrix C. 1239/// \param [in] k Specifies the number of columns of the matrix op(A) and the number of rows of the matrix op(B). 1240/// \param [in] alpha Scaling factor for the matrix-matrix product. 1241/// \param [in] a Input matrix A. 1242/// \param [in] a_type Data type of the matrix A. 1243/// \param [in] lda Leading dimension of A. 1244/// \param [in] stride_a Stride between the different A matrices. 1245/// \param [in] b Input matrix B. 1246/// \param [in] b_type Data type of the matrix B. 1247/// \param [in] ldb Leading dimension of B. 1248/// \param [in] stride_b Stride between the different B matrices. 1249/// \param [in] beta Scaling factor for matrix C. 1250/// \param [in, out] c Input/Output matrix C. 1251/// \param [in] c_type Data type of the matrix C. 1252/// \param [in] ldc Leading dimension of C. 1253/// \param [in] stride_c Stride between the different C matrices. 1254/// \param [in] batch_size Specifies the number of matrix multiply operations to perform. 1255/// \param [in] ct Compute type. 1256inline void gemm_batch (descriptor_ptr desc_ptr , oneapi::mkl::transpose a_trans , 1257oneapi::mkl::transpose b_trans , std::int64_t m , 1258std::int64_t n , std::int64_t k , const void * alpha , 1259const void * a , library_data_t a_type , std::int64_t lda , 1260long long int stride_a , const void * b , 1261library_data_t b_type , std::int64_t ldb , 1262long long int stride_b , const void * beta , void * c , 1263library_data_t c_type , std::int64_t ldc , 1264long long int stride_c , std::int64_t batch_size , 1265std::variant < compute_type, library_data_t > ct ) { 1266sycl::queue q = desc_ptr -> get_queue (); 1267#ifdef __INTEL_MKL__ 1268oneapi::mkl::blas::compute_mode cm = oneapi::mkl::blas::compute_mode:: unset ; 1269#endif 1270library_data_t scaling_type ; 1271if (auto ct_p = std:: get_if < compute_type > ( & ct )) { 1272#ifdef __INTEL_MKL__ 1273cm = deduce_compute_mode ( * ct_p , desc_ptr -> get_math_mode (), 1274a_type == library_data_t:: complex_float || 1275a_type == library_data_t:: complex_double ); 1276#endif 1277scaling_type = detail:: compute_type_to_library_data_t ( * ct_p ); 1278} else { 1279#ifdef __INTEL_MKL__ 1280cm = deduce_compute_mode (std:: nullopt , desc_ptr -> get_math_mode (), 1281a_type == library_data_t:: complex_float || 1282a_type == library_data_t:: complex_double ); 1283#endif 1284scaling_type = std:: get < library_data_t > ( ct ); 1285} 1286 1287if ( scaling_type == library_data_t:: real_float && 1288c_type == library_data_t:: complex_float ) { 1289scaling_type = library_data_t:: complex_float ; 1290} else if ( scaling_type == library_data_t:: real_double && 1291c_type == library_data_t:: complex_double ) { 1292scaling_type = library_data_t:: complex_double ; 1293} 1294 1295std::uint64_t key = dpct::detail:: get_type_combination_id ( 1296a_type , b_type , c_type , scaling_type ); 1297switch ( key ) { 1298case dpct::detail:: get_type_combination_id ( 1299library_data_t:: real_float , library_data_t:: real_float , 1300library_data_t:: real_float , library_data_t:: real_float ): { 1301dpct::detail:: gemm_batch_impl < float, float, float, float > ( 1302q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b, 1303beta, c, ldc, stride_c, batch_size DPCT_COMPUTE_MODE_ARG ); 1304break ; 1305} 1306case dpct::detail:: get_type_combination_id ( 1307library_data_t:: real_double , library_data_t:: real_double , 1308library_data_t:: real_double , library_data_t:: real_double ): { 1309dpct::detail:: gemm_batch_impl < double, double, double, double > ( 1310q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b, 1311beta, c, ldc, stride_c, batch_size DPCT_COMPUTE_MODE_ARG ); 1312break ; 1313} 1314case dpct::detail:: get_type_combination_id ( 1315library_data_t:: complex_float , library_data_t:: complex_float , 1316library_data_t:: complex_float , library_data_t:: complex_float ): { 1317dpct::detail:: gemm_batch_impl < std::complex < float > , std::complex < float > , 1318std::complex < float > , std::complex < float >> ( 1319q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b, 1320beta, c, ldc, stride_c, batch_size DPCT_COMPUTE_MODE_ARG ); 1321break ; 1322} 1323case dpct::detail:: get_type_combination_id ( 1324library_data_t:: complex_double , library_data_t:: complex_double , 1325library_data_t:: complex_double , library_data_t:: complex_double ): { 1326dpct::detail:: gemm_batch_impl < std::complex < double > , std::complex < double > , 1327std::complex < double > , std::complex < double >> ( 1328q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b, 1329beta, c, ldc, stride_c, batch_size DPCT_COMPUTE_MODE_ARG ); 1330break ; 1331} 1332case dpct::detail:: get_type_combination_id ( 1333library_data_t:: real_half , library_data_t:: real_half , 1334library_data_t:: real_half , library_data_t:: real_half ): { 1335dpct::detail:: gemm_batch_impl < sycl::half, sycl::half, sycl::half, 1336sycl::half > ( 1337q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b, 1338beta, c, ldc, stride_c, batch_size DPCT_COMPUTE_MODE_ARG ); 1339break ; 1340} 1341#ifdef __INTEL_MKL__ 1342case dpct::detail:: get_type_combination_id ( 1343library_data_t:: real_bfloat16 , library_data_t:: real_bfloat16 , 1344library_data_t:: real_bfloat16 , library_data_t:: real_float ): { 1345dpct::detail:: gemm_batch_impl < oneapi::mkl::bfloat16, oneapi::mkl::bfloat16, 1346oneapi::mkl::bfloat16, float > ( 1347q , a_trans , b_trans , m , n , k , alpha , a , lda , stride_a , b , ldb , stride_b , 1348beta , c , ldc , stride_c , batch_size , cm ); 1349break ; 1350} 1351case dpct::detail:: get_type_combination_id ( 1352library_data_t:: real_bfloat16 , library_data_t:: real_bfloat16 , 1353library_data_t:: real_float , library_data_t:: real_float ): { 1354dpct::detail:: gemm_batch_impl < oneapi::mkl::bfloat16, oneapi::mkl::bfloat16, 1355float, float > ( 1356q , a_trans , b_trans , m , n , k , alpha , a , lda , stride_a , b , ldb , stride_b , 1357beta , c , ldc , stride_c , batch_size , cm ); 1358break ; 1359} 1360#endif 1361case dpct::detail:: get_type_combination_id ( 1362library_data_t:: real_int8 , library_data_t:: real_int8 , 1363library_data_t:: real_int32 , library_data_t:: real_int32 ): { 1364float alpha_float = 1365dpct:: get_value ( reinterpret_cast < const std::int32_t *> ( alpha ), q ); 1366float beta_float = 1367dpct:: get_value ( reinterpret_cast < const std::int32_t *> ( beta ), q ); 1368dpct::detail:: gemm_batch_impl < std::int8_t, std::int8_t, std::int32_t, 1369float > ( 1370q , a_trans , b_trans , m , n , k , & alpha_float , a , lda , stride_a , b , ldb , 1371stride_b , & beta_float , c , ldc , stride_c , 1372batch_size DPCT_COMPUTE_MODE_ARG ); 1373break ; 1374} 1375case dpct::detail:: get_type_combination_id ( 1376library_data_t:: real_int8 , library_data_t:: real_int8 , 1377library_data_t:: real_float , library_data_t:: real_float ): { 1378dpct::detail:: gemm_batch_impl < std::int8_t, std::int8_t, float, float > ( 1379q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b, 1380beta, c, ldc, stride_c, batch_size DPCT_COMPUTE_MODE_ARG ); 1381break ; 1382} 1383case dpct::detail:: get_type_combination_id ( 1384library_data_t:: real_half , library_data_t:: real_half , 1385library_data_t:: real_float , library_data_t:: real_float ): { 1386dpct::detail:: gemm_batch_impl < sycl::half, sycl::half, float, float > ( 1387q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b, 1388beta, c, ldc, stride_c, batch_size DPCT_COMPUTE_MODE_ARG ); 1389break ; 1390} 1391case dpct::detail:: get_type_combination_id ( 1392library_data_t:: real_half , library_data_t:: real_half , 1393library_data_t:: real_half , library_data_t:: real_float ): { 1394float alpha_value = 1395dpct:: get_value ( reinterpret_cast < const float *> ( alpha ), q ); 1396float beta_value = 1397dpct:: get_value ( reinterpret_cast < const float *> ( beta ), q ); 1398sycl::half alpha_half (alpha_value); 1399sycl::half beta_half (beta_value); 1400dpct::detail:: gemm_batch_impl < sycl::half, sycl::half, sycl::half, 1401sycl::half > ( 1402q , a_trans , b_trans , m , n , k , & alpha_half , a , lda , stride_a , b , ldb , 1403stride_b , & beta_half , c , ldc , stride_c , batch_size DPCT_COMPUTE_MODE_ARG ); 1404break ; 1405} 1406default : 1407throw std:: runtime_error ( "the combination of data type is unsupported" ); 1408} 1409} 1410 1411/// Performs a symmetric/hermitian rank-k update. 1412/// \tparam is_hermitian True means current matrix is hermitian. 1413/// \param [in] desc_ptr Descriptor. 1414/// \param [in] uplo Specifies whether matrix c is upper or lower triangular. 1415/// \param [in] trans Specifies op(a), the transposition operation applied to 1416/// matrix a. 1417/// \param [in] n Number of rows and columns of matrix c. 1418/// \param [in] k Number of columns of matrix op(a). 1419/// \param [in] alpha Scaling factor for the rank-k update. 1420/// \param [in] a Input matrix a. 1421/// \param [in] a_type Data type of the matrix a. 1422/// \param [in] lda Leading dimension of the matrix a. 1423/// \param [in] beta Scaling factor for the rank-k update. 1424/// \param [in, out] c Input/Output matrix c. 1425/// \param [in] c_type Data type of the matrix c. 1426/// \param [in] ldc Leading dimension of the matrix c. 1427/// \param [in] ct Compute type. 1428template < bool is_hermitian > 1429inline void syherk (descriptor_ptr desc_ptr , oneapi::mkl::uplo uplo , 1430oneapi::mkl::transpose trans , std::int64_t n , std::int64_t k , 1431const void * alpha , const void * a , library_data_t a_type , 1432std::int64_t lda , const void * beta , void * c , 1433library_data_t c_type , std::int64_t ldc , 1434std::variant < compute_type, library_data_t > ct ) { 1435sycl::queue q = desc_ptr -> get_queue (); 1436#ifdef __INTEL_MKL__ 1437oneapi::mkl::blas::compute_mode cm = oneapi::mkl::blas::compute_mode:: unset ; 1438if (auto ct_p = std:: get_if < compute_type > ( & ct )) { 1439cm = deduce_compute_mode ( * ct_p , desc_ptr -> get_math_mode (), 1440a_type == library_data_t:: complex_float || 1441a_type == library_data_t:: complex_double ); 1442} else { 1443cm = deduce_compute_mode (std:: nullopt , desc_ptr -> get_math_mode (), 1444a_type == library_data_t:: complex_float || 1445a_type == library_data_t:: complex_double ); 1446} 1447#endif 1448std::uint64_t key = dpct::detail:: get_type_combination_id ( a_type , c_type ); 1449if (! is_hermitian && 1450dpct::detail:: get_type_combination_id ( 1451library_data_t:: real_float , library_data_t:: real_float ) == key ) { 1452dpct::detail:: syherk_impl < false, float > (q, uplo, trans, n, k, alpha, a, lda, 1453beta, c, ldc DPCT_COMPUTE_MODE_ARG ); 1454} else if (! is_hermitian && dpct::detail:: get_type_combination_id ( 1455library_data_t:: real_double , 1456library_data_t:: real_double ) == key ) { 1457dpct::detail:: syherk_impl < false, double > (q, uplo, trans, n, k, alpha, a, 1458lda, beta, c, 1459ldc DPCT_COMPUTE_MODE_ARG ); 1460} else if (dpct::detail:: get_type_combination_id ( 1461library_data_t:: complex_float , 1462library_data_t:: complex_float ) == key ) { 1463dpct::detail:: syherk_impl < is_hermitian, std::complex < float >> ( 1464q, uplo, trans, n, k, alpha, a, lda, beta, c, 1465ldc DPCT_COMPUTE_MODE_ARG ); 1466} else if (dpct::detail:: get_type_combination_id ( 1467library_data_t:: complex_double , 1468library_data_t:: complex_double ) == key ) { 1469dpct::detail:: syherk_impl < is_hermitian, std::complex < double >> ( 1470q, uplo, trans, n, k, alpha, a, lda, beta, c, 1471ldc DPCT_COMPUTE_MODE_ARG ); 1472} else { 1473throw std:: runtime_error ( "the combination of data type is unsupported" ); 1474} 1475} 1476 1477/// This routines perform a special rank-k update of a symmetric matrix C by 1478/// general matrices A and B. 1479/// \param [in] desc_ptr Descriptor. 1480/// \param [in] uplo Specifies whether C's data is stored in its upper or lower triangle. 1481/// \param [in] trans Specifies the operation to apply. 1482/// \param [in] n The number of rows and columns in C. 1483/// \param [in] k The inner dimension of matrix multiplications. 1484/// \param [in] alpha Scaling factor for the rank-k update. 1485/// \param [in] a Input matrix A. 1486/// \param [in] lda Leading dimension of A. 1487/// \param [in] b Input matrix B. 1488/// \param [in] ldb Leading dimension of B. 1489/// \param [in] beta Scaling factor for the rank-k update. 1490/// \param [in, out] c Input/Output matrix C. 1491/// \param [in] ldc Leading dimension of C. 1492template < class T > 1493inline void syrk (descriptor_ptr desc_ptr , oneapi::mkl::uplo uplo , 1494oneapi::mkl::transpose trans , std::int64_t n , std::int64_t k , 1495const T * alpha , const T * a , std::int64_t lda , const T * b , 1496std::int64_t ldb , const T * beta , T * c , std::int64_t ldc ) { 1497sycl::queue q = desc_ptr -> get_queue (); 1498#ifdef __INTEL_MKL__ 1499auto cm = deduce_compute_mode < T > (std:: nullopt , desc_ptr -> get_math_mode ()); 1500#endif 1501dpct::detail:: rk_impl < false, T, T > (q, uplo, trans, n, k, alpha, a, lda, b, 1502ldb, beta, c, ldc DPCT_COMPUTE_MODE_ARG ); 1503} 1504 1505/// This routines perform a special rank-k update of a Hermitian matrix C by 1506/// general matrices A and B. 1507/// \param [in] desc_ptr Descriptor. 1508/// \param [in] uplo Specifies whether C's data is stored in its upper or lower triangle. 1509/// \param [in] trans Specifies the operation to apply. 1510/// \param [in] n The number of rows and columns in C. 1511/// \param [in] k The inner dimension of matrix multiplications. 1512/// \param [in] alpha Scaling factor for the rank-k update. 1513/// \param [in] a Input matrix A. 1514/// \param [in] lda Leading dimension of A. 1515/// \param [in] b Input matrix B. 1516/// \param [in] ldb Leading dimension of B. 1517/// \param [in] beta Scaling factor for the rank-k update. 1518/// \param [in, out] c Input/Output matrix C. 1519/// \param [in] ldc Leading dimension of C. 1520template < class T, class Tbeta > 1521inline void herk (descriptor_ptr desc_ptr , oneapi::mkl::uplo uplo , 1522oneapi::mkl::transpose trans , std::int64_t n , std::int64_t k , 1523const T * alpha , const T * a , std::int64_t lda , const T * b , 1524std::int64_t ldb , const Tbeta * beta , T * c , std::int64_t ldc ) { 1525sycl::queue q = desc_ptr -> get_queue (); 1526#ifdef __INTEL_MKL__ 1527auto cm = deduce_compute_mode < T > (std:: nullopt , desc_ptr -> get_math_mode ()); 1528#endif 1529dpct::detail:: rk_impl < true, T, Tbeta > (q, uplo, trans, n, k, alpha, a, lda, b, 1530ldb, beta, c, 1531ldc DPCT_COMPUTE_MODE_ARG ); 1532} 1533 1534/// This routine performs a group of trsm operations. Each trsm solves an 1535/// equation of the form op(A) * X = alpha * B or X * op(A) = alpha * B. 1536/// \param [in] desc_ptr Descriptor. 1537/// \param [in] left_right Specifies A multiplies X on the left or on the right. 1538/// \param [in] upper_lower Specifies A is upper or lower triangular. 1539/// \param [in] trans Specifies the operation applied to A. 1540/// \param [in] unit_diag Specifies whether A is unit triangular. 1541/// \param [in] m Number of rows of the B matrices. 1542/// \param [in] n Number of columns of the B matrices. 1543/// \param [in] alpha Scaling factor for the solutions. 1544/// \param [in] a Input matrices A. 1545/// \param [in] a_type Data type of the matrices A. 1546/// \param [in] lda Leading dimension of the matrices A. 1547/// \param [in, out] b Input and output matrices B. 1548/// \param [in] b_type Data type of the matrices B. 1549/// \param [in] ldb Leading dimension of the matrices B. 1550/// \param [in] batch_size Specifies the number of trsm operations to perform. 1551/// \param [in] ct Compute type. 1552inline void trsm_batch (descriptor_ptr desc_ptr , oneapi::mkl::side left_right , 1553oneapi::mkl::uplo upper_lower , 1554oneapi::mkl::transpose trans , 1555oneapi::mkl::diag unit_diag , std::int64_t m , 1556std::int64_t n , const void * alpha , const void ** a , 1557library_data_t a_type , std::int64_t lda , void ** b , 1558library_data_t b_type , std::int64_t ldb , 1559std::int64_t batch_size , 1560std::variant < compute_type, library_data_t > ct ) { 1561#ifdef DPCT_USM_LEVEL_NONE 1562throw std:: runtime_error ( "this API is unsupported when USM level is none" ); 1563#else 1564sycl::queue q = desc_ptr -> get_queue (); 1565#ifdef __INTEL_MKL__ 1566oneapi::mkl::blas::compute_mode cm = oneapi::mkl::blas::compute_mode:: unset ; 1567if (auto ct_p = std:: get_if < compute_type > ( & ct )) 1568cm = deduce_compute_mode ( * ct_p , desc_ptr -> get_math_mode (), 1569a_type == library_data_t:: complex_float || 1570a_type == library_data_t:: complex_double ); 1571else 1572cm = deduce_compute_mode (std:: nullopt , desc_ptr -> get_math_mode (), 1573a_type == library_data_t:: complex_float || 1574a_type == library_data_t:: complex_double ); 1575#endif 1576std::uint64_t key = dpct::detail:: get_type_combination_id ( a_type , b_type ); 1577switch ( key ) { 1578case dpct::detail:: get_type_combination_id (library_data_t:: real_float , 1579library_data_t:: real_float ): { 1580dpct::detail:: trsm_batch_impl < float, float, float > ( 1581q, left_right, upper_lower, trans, unit_diag, m, n, alpha, a, lda, b, 1582ldb, batch_size DPCT_COMPUTE_MODE_ARG ); 1583break ; 1584} 1585case dpct::detail:: get_type_combination_id (library_data_t:: real_double , 1586library_data_t:: real_double ): { 1587dpct::detail:: trsm_batch_impl < double, double, double > ( 1588q, left_right, upper_lower, trans, unit_diag, m, n, alpha, a, lda, b, 1589ldb, batch_size DPCT_COMPUTE_MODE_ARG ); 1590break ; 1591} 1592case dpct::detail:: get_type_combination_id (library_data_t:: complex_float , 1593library_data_t:: complex_float ): { 1594dpct::detail:: trsm_batch_impl < std::complex < float > , std::complex < float > , 1595std::complex < float >> ( 1596q, left_right, upper_lower, trans, unit_diag, m, n, alpha, a, lda, b, 1597ldb, batch_size DPCT_COMPUTE_MODE_ARG ); 1598break ; 1599} 1600case dpct::detail:: get_type_combination_id (library_data_t:: complex_double , 1601library_data_t:: complex_double ): { 1602dpct::detail:: trsm_batch_impl < std::complex < double > , std::complex < double > , 1603std::complex < double >> ( 1604q, left_right, upper_lower, trans, unit_diag, m, n, alpha, a, lda, b, 1605ldb, batch_size DPCT_COMPUTE_MODE_ARG ); 1606break ; 1607} 1608default : 1609throw std:: runtime_error ( "the combination of data type is unsupported" ); 1610} 1611#endif 1612} 1613 1614/// Computes a triangular matrix-general matrix product. 1615/// \param [in] desc_ptr Descriptor. 1616/// \param [in] left_right Specifies A is on the left or right side of the 1617/// multiplication. 1618/// \param [in] upper_lower Specifies A is upper or lower triangular. 1619/// \param [in] trans Specifies the operation applied to A. 1620/// \param [in] unit_diag Specifies whether A is unit triangular. 1621/// \param [in] m Number of rows of B. 1622/// \param [in] n Number of columns of B. 1623/// \param [in] alpha Scaling factor for the matrix-matrix product. 1624/// \param [in] a Input matrices A. 1625/// \param [in] lda Leading dimension of the matrices A. 1626/// \param [in] b Input matrices B. 1627/// \param [in] ldb Leading dimension of the matrices B. 1628/// \param [out] c Output matrices C. 1629/// \param [in] ldc Leading dimension of the matrices C. 1630template < class T > 1631inline void trmm (descriptor_ptr desc_ptr , oneapi::mkl::side left_right , 1632oneapi::mkl::uplo upper_lower , oneapi::mkl::transpose trans , 1633oneapi::mkl::diag unit_diag , std::int64_t m , std::int64_t n , 1634const T * alpha , const T * a , std::int64_t lda , const T * b , 1635std::int64_t ldb , T * c , std::int64_t ldc ) { 1636using Ty = typename ::dpct::detail::lib_data_traits_t < T > ; 1637sycl::queue q = desc_ptr -> get_queue (); 1638#ifdef __INTEL_MKL__ 1639auto cm = deduce_compute_mode < Ty > (std:: nullopt , desc_ptr -> get_math_mode ()); 1640#endif 1641auto alpha_val = dpct:: get_value ( alpha , q ); 1642if ( b != c ) { 1643dpct::blas:: matrix_mem_copy ( c , b , ldc , ldb , m , n , sizeof ( Ty ), 1644::dpct::cs::memcpy_direction:: device_to_device , 1645q ); 1646} 1647auto data_a = dpct::detail:: get_memory < const Ty > ( a ); 1648auto data_c = dpct::detail:: get_memory < Ty > ( c ); 1649oneapi::mkl::blas::column_major:: trmm (q, left_right, upper_lower, trans, 1650unit_diag, m, n, alpha_val, data_a, lda, 1651data_c, ldc DPCT_COMPUTE_MODE_ARG ); 1652} 1653 1654/// Computes the Euclidean norm of a vector. 1655/// \param [in] desc_ptr Descriptor. 1656/// \param [in] n Number of elements in vector x. 1657/// \param [in] x Input vector x. 1658/// \param [in] x_type Data type of the vector x. 1659/// \param [in] incx Stride of vector x. 1660/// \param [out] result The result scalar. 1661/// \param [in] result_type Data type of the result. 1662inline void nrm2 (descriptor_ptr desc_ptr , std::int64_t n , const void * x , 1663library_data_t x_type , std::int64_t incx , void * result , 1664library_data_t result_type ) { 1665sycl::queue q = desc_ptr -> get_queue (); 1666std::uint64_t key = 1667::dpct::detail:: get_type_combination_id ( x_type , result_type ); 1668switch ( key ) { 1669case ::dpct::detail:: get_type_combination_id (library_data_t:: real_float , 1670library_data_t:: real_float ): { 1671::dpct::detail:: nrm2_impl < float, float > ( q , n , x , incx , result ); 1672break ; 1673} 1674case ::dpct::detail:: get_type_combination_id (library_data_t:: real_double , 1675library_data_t:: real_double ): { 1676::dpct::detail:: nrm2_impl < double, double > ( q , n , x , incx , result ); 1677break ; 1678} 1679case ::dpct::detail:: get_type_combination_id (library_data_t:: complex_float , 1680library_data_t:: real_float ): { 1681::dpct::detail:: nrm2_impl < std::complex < float > , float > ( q , n , x , incx , 1682result ); 1683break ; 1684} 1685case ::dpct::detail:: get_type_combination_id (library_data_t:: complex_double , 1686library_data_t:: real_double ): { 1687::dpct::detail:: nrm2_impl < std::complex < double > , double > ( q , n , x , incx , 1688result ); 1689break ; 1690} 1691#ifdef __INTEL_MKL__ 1692case ::dpct::detail:: get_type_combination_id (library_data_t:: real_half , 1693library_data_t:: real_half ): { 1694::dpct::detail:: nrm2_impl < sycl::half, sycl::half > ( q , n , x , incx , result ); 1695break ; 1696} 1697#endif 1698default : 1699throw std:: runtime_error ( "the combination of data type is unsupported" ); 1700} 1701} 1702 1703/// Computes the dot product of two vectors. 1704/// \param [in] desc_ptr Descriptor. 1705/// \param [in] n Number of elements in vector x. 1706/// \param [in] x Input vector x. 1707/// \param [in] x_type Data type of the vector x. 1708/// \param [in] incx Stride of vector x. 1709/// \param [in] y Input vector y. 1710/// \param [in] y_type Data type of the vector y. 1711/// \param [in] incy Stride of vector y. 1712/// \param [out] result The result scalar. 1713/// \param [in] result_type Data type of the result. 1714inline void dot (descriptor_ptr desc_ptr , std::int64_t n , const void * x , 1715library_data_t x_type , std::int64_t incx , const void * y , 1716library_data_t y_type , std::int64_t incy , void * result , 1717library_data_t result_type ) { 1718sycl::queue q = desc_ptr -> get_queue (); 1719::dpct::detail:: dotuc < false > ( q , n , x , x_type , incx , y , y_type , incy , result , 1720result_type ); 1721} 1722 1723/// Computes the dot product of two vectors, conjugating the first vector. 1724/// \param [in] desc_ptr Descriptor. 1725/// \param [in] n Number of elements in vector x. 1726/// \param [in] x Input vector x. 1727/// \param [in] x_type Data type of the vector x. 1728/// \param [in] incx Stride of vector x. 1729/// \param [in] y Input vector y. 1730/// \param [in] y_type Data type of the vector y. 1731/// \param [in] incy Stride of vector y. 1732/// \param [out] result The result scalar. 1733/// \param [in] result_type Data type of the result. 1734inline void dotc (descriptor_ptr desc_ptr , std::int64_t n , const void * x , 1735library_data_t x_type , std::int64_t incx , const void * y , 1736library_data_t y_type , std::int64_t incy , void * result , 1737library_data_t result_type ) { 1738sycl::queue q = desc_ptr -> get_queue (); 1739::dpct::detail:: dotuc < true > ( q , n , x , x_type , incx , y , y_type , incy , result , 1740result_type ); 1741} 1742 1743/// Computes the product of a vector by a scalar. 1744/// \param [in] desc_ptr Descriptor. 1745/// \param [in] n Number of elements in vector x. 1746/// \param [in] alpha The scale factor alpha. 1747/// \param [in] alpha_type The data type of alpha. 1748/// \param [in, out] x Input/Output vector x. 1749/// \param [in] x_type Data type of the vector x. 1750/// \param [in] incx Stride of vector x. 1751inline void scal (descriptor_ptr desc_ptr , std::int64_t n , const void * alpha , 1752library_data_t alpha_type , void * x , library_data_t x_type , 1753std::int64_t incx ) { 1754sycl::queue q = desc_ptr -> get_queue (); 1755std::uint64_t key = ::dpct::detail:: get_type_combination_id ( x_type ); 1756switch ( key ) { 1757case ::dpct::detail:: get_type_combination_id (library_data_t:: real_float ): { 1758::dpct::detail:: scal_impl < float, float > ( q , n , alpha , x , incx ); 1759break ; 1760} 1761case ::dpct::detail:: get_type_combination_id (library_data_t:: real_double ): { 1762::dpct::detail:: scal_impl < double, double > ( q , n , alpha , x , incx ); 1763break ; 1764} 1765case ::dpct::detail:: get_type_combination_id (library_data_t:: complex_float ): { 1766::dpct::detail:: scal_impl < std::complex < float > , std::complex < float >> ( 1767q , n , alpha , x , incx ); 1768break ; 1769} 1770case ::dpct::detail:: get_type_combination_id ( 1771library_data_t:: complex_double ): { 1772::dpct::detail:: scal_impl < std::complex < double > , std::complex < double >> ( 1773q , n , alpha , x , incx ); 1774break ; 1775} 1776#ifdef __INTEL_MKL__ 1777case ::dpct::detail:: get_type_combination_id (library_data_t:: real_half ): { 1778float alpha_value = 1779dpct:: get_value ( reinterpret_cast < const float *> ( alpha ), q ); 1780sycl::half alaph_half (alpha_value); 1781::dpct::detail:: scal_impl < sycl::half, sycl::half > ( q , n , & alaph_half , x , 1782incx ); 1783break ; 1784} 1785#endif 1786default : 1787throw std:: runtime_error ( "the combination of data type is unsupported" ); 1788} 1789} 1790 1791/// Computes a vector-scalar product and adds the result to a vector. 1792/// \param [in] desc_ptr Descriptor. 1793/// \param [in] n Number of elements in vector x. 1794/// \param [in] alpha The scale factor alpha. 1795/// \param [in] alpha_type The data type of alpha. 1796/// \param [in] x Input vector x. 1797/// \param [in] x_type Data type of the vector x. 1798/// \param [in] incx Stride of vector x. 1799/// \param [in, out] y Input/Output vector y. 1800/// \param [in] y_type Data type of the vector y. 1801/// \param [in] incy Stride of vector y. 1802inline void axpy (descriptor_ptr desc_ptr , std::int64_t n , const void * alpha , 1803library_data_t alpha_type , const void * x , 1804library_data_t x_type , std::int64_t incx , void * y , 1805library_data_t y_type , std::int64_t incy ) { 1806sycl::queue q = desc_ptr -> get_queue (); 1807std::uint64_t key = 1808::dpct::detail:: get_type_combination_id ( x_type , alpha_type ); 1809switch ( key ) { 1810case ::dpct::detail:: get_type_combination_id (library_data_t:: real_float , 1811library_data_t:: real_float ): { 1812::dpct::detail:: axpy_impl < float, float > ( q , n , alpha , x , incx , y , incy ); 1813break ; 1814} 1815case ::dpct::detail:: get_type_combination_id (library_data_t:: real_double , 1816library_data_t:: real_double ): { 1817::dpct::detail:: axpy_impl < double, double > ( q , n , alpha , x , incx , y , incy ); 1818break ; 1819} 1820case ::dpct::detail:: get_type_combination_id (library_data_t:: complex_float , 1821library_data_t:: complex_float ): { 1822::dpct::detail:: axpy_impl < std::complex < float > , std::complex < float >> ( 1823q , n , alpha , x , incx , y , incy ); 1824break ; 1825} 1826case ::dpct::detail:: get_type_combination_id ( 1827library_data_t:: complex_double , library_data_t:: complex_double ): { 1828::dpct::detail:: axpy_impl < std::complex < double > , std::complex < double >> ( 1829q , n , alpha , x , incx , y , incy ); 1830break ; 1831} 1832#ifdef __INTEL_MKL__ 1833case ::dpct::detail:: get_type_combination_id (library_data_t:: real_half , 1834library_data_t:: real_float ): { 1835float alpha_value = 1836dpct:: get_value ( reinterpret_cast < const float *> ( alpha ), q ); 1837sycl::half alaph_half (alpha_value); 1838::dpct::detail:: axpy_impl < sycl::half, sycl::half > ( q , n , & alaph_half , x , 1839incx , y , incy ); 1840break ; 1841} 1842#endif 1843default : 1844throw std:: runtime_error ( "the combination of data type is unsupported" ); 1845} 1846} 1847 1848/// Performs rotation of points in the plane. 1849/// \param [in] desc_ptr Descriptor. 1850/// \param [in] n Number of elements in vector x. 1851/// \param [in, out] x Input/Output vector x. 1852/// \param [in] x_type Data type of the vector x. 1853/// \param [in] incx Stride of vector x. 1854/// \param [in, out] y Input/Output vector y. 1855/// \param [in] y_type Data type of the vector y. 1856/// \param [in] incy Stride of vector y. 1857/// \param [in] c Scaling factor. 1858/// \param [in] s Scaling factor. 1859/// \param [in] cs_type Data type of the scaling factors. 1860inline void rot (descriptor_ptr desc_ptr , std::int64_t n , void * x , 1861library_data_t x_type , std::int64_t incx , void * y , 1862library_data_t y_type , std::int64_t incy , const void * c , 1863const void * s , library_data_t cs_type ) { 1864sycl::queue q = desc_ptr -> get_queue (); 1865std::uint64_t key = ::dpct::detail:: get_type_combination_id ( x_type , cs_type ); 1866switch ( key ) { 1867case ::dpct::detail:: get_type_combination_id (library_data_t:: real_float , 1868library_data_t:: real_float ): { 1869::dpct::detail:: rot_impl < float, float, float > ( q , n , x , incx , y , incy , c , s ); 1870break ; 1871} 1872case ::dpct::detail:: get_type_combination_id (library_data_t:: real_double , 1873library_data_t:: real_double ): { 1874::dpct::detail:: rot_impl < double, double, double > ( q , n , x , incx , y , incy , c , 1875s ); 1876break ; 1877} 1878case ::dpct::detail:: get_type_combination_id (library_data_t:: complex_float , 1879library_data_t:: real_float ): { 1880::dpct::detail:: rot_impl < std::complex < float > , float, float > ( q , n , x , incx , 1881y , incy , c , s ); 1882break ; 1883} 1884case ::dpct::detail:: get_type_combination_id (library_data_t:: complex_double , 1885library_data_t:: real_double ): { 1886::dpct::detail:: rot_impl < std::complex < double > , double, double > ( 1887q , n , x , incx , y , incy , c , s ); 1888break ; 1889} 1890#ifdef __INTEL_MKL__ 1891case ::dpct::detail:: get_type_combination_id (library_data_t:: complex_float , 1892library_data_t:: complex_float ): { 1893::dpct::detail:: rot_impl < std::complex < float > , float, std::complex < float >> ( 1894q , n , x , incx , y , incy , c , s ); 1895break ; 1896} 1897case ::dpct::detail:: get_type_combination_id ( 1898library_data_t:: complex_double , library_data_t:: complex_double ): { 1899::dpct::detail:: rot_impl < std::complex < double > , double, 1900std::complex < double >> ( q , n , x , incx , y , incy , c , 1901s ); 1902break ; 1903} 1904case ::dpct::detail:: get_type_combination_id (library_data_t:: real_half , 1905library_data_t:: real_half ): { 1906::dpct::detail:: rot_impl < sycl::half, sycl::half, sycl::half > ( q , n , x , incx , 1907y , incy , c , s ); 1908break ; 1909} 1910case ::dpct::detail:: get_type_combination_id (library_data_t:: real_bfloat16 , 1911library_data_t:: real_bfloat16 ): { 1912::dpct::detail:: rot_impl < oneapi::mkl::bfloat16, oneapi::mkl::bfloat16, 1913oneapi::mkl::bfloat16 > ( q , n , x , incx , y , incy , c , 1914s ); 1915break ; 1916} 1917#endif 1918default : 1919throw std:: runtime_error ( "the combination of data type is unsupported" ); 1920} 1921} 1922 1923/// Performs modified Givens rotation of points in the plane. 1924/// \param [in] desc_ptr Descriptor. 1925/// \param [in] n Number of elements in vector x. 1926/// \param [in, out] x Input/Output vector x. 1927/// \param [in] x_type Data type of the vector x. 1928/// \param [in] incx Stride of vector x. 1929/// \param [in, out] y Input/Output vector y. 1930/// \param [in] y_type Data type of the vector y. 1931/// \param [in] incy Stride of vector y. 1932/// \param [in] param Array of 5 parameters. 1933/// \param [in] param_type Data type of \p param. 1934inline void rotm (descriptor_ptr desc_ptr , std::int64_t n , void * x , 1935library_data_t x_type , int64_t incx , void * y , 1936library_data_t y_type , int64_t incy , const void * param , 1937library_data_t param_type ) { 1938sycl::queue q = desc_ptr -> get_queue (); 1939std::uint64_t key = 1940::dpct::detail:: get_type_combination_id ( x_type , param_type ); 1941switch ( key ) { 1942case ::dpct::detail:: get_type_combination_id (library_data_t:: real_float , 1943library_data_t:: real_float , 1944library_data_t:: real_float ): { 1945::dpct::detail:: rotm_impl < float, float, float > ( q , n , x , incx , y , incy , 1946param ); 1947break ; 1948} 1949case ::dpct::detail:: get_type_combination_id (library_data_t:: real_double , 1950library_data_t:: real_double , 1951library_data_t:: real_double ): { 1952::dpct::detail:: rotm_impl < double, double, double > ( q , n , x , incx , y , incy , 1953param ); 1954break ; 1955} 1956default : 1957throw std:: runtime_error ( "the combination of data type is unsupported" ); 1958} 1959} 1960 1961/// Copies a vector to another vector. 1962/// \param [in] desc_ptr Descriptor. 1963/// \param [in] n Number of elements in vector x. 1964/// \param [in] x Input vector x. 1965/// \param [in] x_type Data type of the vector x. 1966/// \param [in] incx Stride of vector x. 1967/// \param [out] y Output vector y. 1968/// \param [in] y_type Data type of the vector y. 1969/// \param [in] incy Stride of vector y. 1970inline void copy (descriptor_ptr desc_ptr , std::int64_t n , const void * x , 1971library_data_t x_type , std::int64_t incx , void * y , 1972library_data_t y_type , std::int64_t incy ) { 1973sycl::queue q = desc_ptr -> get_queue (); 1974std::uint64_t key = ::dpct::detail:: get_type_combination_id ( x_type , y_type ); 1975switch ( key ) { 1976case ::dpct::detail:: get_type_combination_id (library_data_t:: real_float , 1977library_data_t:: real_float ): { 1978::dpct::detail:: copy_impl < float, float > ( q , n , x , incx , y , incy ); 1979break ; 1980} 1981case ::dpct::detail:: get_type_combination_id (library_data_t:: real_double , 1982library_data_t:: real_double ): { 1983::dpct::detail:: copy_impl < double, double > ( q , n , x , incx , y , incy ); 1984break ; 1985} 1986case ::dpct::detail:: get_type_combination_id (library_data_t:: complex_float , 1987library_data_t:: complex_float ): { 1988::dpct::detail:: copy_impl < std::complex < float > , std::complex < float >> ( 1989q , n , x , incx , y , incy ); 1990break ; 1991} 1992case ::dpct::detail:: get_type_combination_id ( 1993library_data_t:: complex_double , library_data_t:: complex_double ): { 1994::dpct::detail:: copy_impl < std::complex < double > , std::complex < double >> ( 1995q , n , x , incx , y , incy ); 1996break ; 1997} 1998default : 1999throw std:: runtime_error ( "the combination of data type is unsupported" ); 2000} 2001} 2002 2003/// Swaps a vector with another vector. 2004/// \param [in] desc_ptr Descriptor. 2005/// \param [in] n Number of elements in vector x. 2006/// \param [in, out] x Input/Output vector x. 2007/// \param [in] x_type Data type of the vector x. 2008/// \param [in] incx Stride of vector x. 2009/// \param [in, out] y Input/Output vector y. 2010/// \param [in] y_type Data type of the vector y. 2011/// \param [in] incy Stride of vector y. 2012inline void swap (descriptor_ptr desc_ptr , std::int64_t n , void * x , 2013library_data_t x_type , std::int64_t incx , void * y , 2014library_data_t y_type , std::int64_t incy ) { 2015sycl::queue q = desc_ptr -> get_queue (); 2016std::uint64_t key = ::dpct::detail:: get_type_combination_id ( x_type , y_type ); 2017switch ( key ) { 2018case ::dpct::detail:: get_type_combination_id (library_data_t:: real_float , 2019library_data_t:: real_float ): { 2020::dpct::detail:: swap_impl < float, float > ( q , n , x , incx , y , incy ); 2021break ; 2022} 2023case ::dpct::detail:: get_type_combination_id (library_data_t:: real_double , 2024library_data_t:: real_double ): { 2025::dpct::detail:: swap_impl < double, double > ( q , n , x , incx , y , incy ); 2026break ; 2027} 2028case ::dpct::detail:: get_type_combination_id (library_data_t:: complex_float , 2029library_data_t:: complex_float ): { 2030::dpct::detail:: swap_impl < std::complex < float > , std::complex < float >> ( 2031q , n , x , incx , y , incy ); 2032break ; 2033} 2034case ::dpct::detail:: get_type_combination_id ( 2035library_data_t:: complex_double , library_data_t:: complex_double ): { 2036::dpct::detail:: swap_impl < std::complex < double > , std::complex < double >> ( 2037q , n , x , incx , y , incy ); 2038break ; 2039} 2040default : 2041throw std:: runtime_error ( "the combination of data type is unsupported" ); 2042} 2043} 2044 2045/// Computes the sum of magnitudes of the vector elements. 2046/// \param [in] desc_ptr Descriptor. 2047/// \param [in] n Number of elements in vector x. 2048/// \param [in] x Input vector x. 2049/// \param [in] x_type Data type of the vector x. 2050/// \param [in] incx Stride of vector x. 2051/// \param [out] result The scalar result. 2052/// \param [in] result_type Data type of \p result. 2053inline void asum (descriptor_ptr desc_ptr , std::int64_t n , const void * x , 2054library_data_t x_type , std::int64_t incx , void * result , 2055library_data_t result_type ) { 2056sycl::queue q = desc_ptr -> get_queue (); 2057std::uint64_t key = 2058::dpct::detail:: get_type_combination_id ( x_type , result_type ); 2059switch ( key ) { 2060case ::dpct::detail:: get_type_combination_id (library_data_t:: real_float , 2061library_data_t:: real_float ): { 2062::dpct::detail:: asum_impl < float, float > ( q , n , x , incx , result ); 2063break ; 2064} 2065case ::dpct::detail:: get_type_combination_id (library_data_t:: real_double , 2066library_data_t:: real_double ): { 2067::dpct::detail:: asum_impl < double, double > ( q , n , x , incx , result ); 2068break ; 2069} 2070case ::dpct::detail:: get_type_combination_id (library_data_t:: complex_float , 2071library_data_t:: real_float ): { 2072::dpct::detail:: asum_impl < std::complex < float > , float > ( q , n , x , incx , 2073result ); 2074break ; 2075} 2076case ::dpct::detail:: get_type_combination_id (library_data_t:: complex_double , 2077library_data_t:: real_double ): { 2078::dpct::detail:: asum_impl < std::complex < double > , double > ( q , n , x , incx , 2079result ); 2080break ; 2081} 2082default : 2083throw std:: runtime_error ( "the combination of data type is unsupported" ); 2084} 2085} 2086 2087/// Finds the index of the element with the largest absolute value in a vector. 2088/// \param [in] desc_ptr Descriptor. 2089/// \param [in] n Number of elements in vector x. 2090/// \param [in] x Input vector x. 2091/// \param [in] x_type Data type of the vector x. 2092/// \param [in] incx Stride of vector x. 2093/// \param [out] result The index of the maximal element. 2094inline void iamax (descriptor_ptr desc_ptr , std::int64_t n , const void * x , 2095library_data_t x_type , std::int64_t incx , 2096std::int64_t * result ) { 2097sycl::queue q = desc_ptr -> get_queue (); 2098std::uint64_t key = ::dpct::detail:: get_type_combination_id ( x_type ); 2099switch ( key ) { 2100case ::dpct::detail:: get_type_combination_id (library_data_t:: real_float ): { 2101::dpct::detail:: iamax_impl < float > ( q , n , x , incx , result ); 2102break ; 2103} 2104case ::dpct::detail:: get_type_combination_id (library_data_t:: real_double ): { 2105::dpct::detail:: iamax_impl < double > ( q , n , x , incx , result ); 2106break ; 2107} 2108case ::dpct::detail:: get_type_combination_id (library_data_t:: complex_float ): { 2109::dpct::detail:: iamax_impl < std::complex < float >> ( q , n , x , incx , result ); 2110break ; 2111} 2112case ::dpct::detail:: get_type_combination_id ( 2113library_data_t:: complex_double ): { 2114::dpct::detail:: iamax_impl < std::complex < double >> ( q , n , x , incx , result ); 2115break ; 2116} 2117default : 2118throw std:: runtime_error ( "the combination of data type is unsupported" ); 2119} 2120} 2121 2122/// Finds the index of the element with the smallest absolute value in a vector. 2123/// \param [in] desc_ptr Descriptor. 2124/// \param [in] n Number of elements in vector x. 2125/// \param [in] x Input vector x. 2126/// \param [in] x_type Data type of the vector x. 2127/// \param [in] incx Stride of vector x. 2128/// \param [out] result The index of the minimum element. 2129inline void iamin (descriptor_ptr desc_ptr , std::int64_t n , const void * x , 2130library_data_t x_type , std::int64_t incx , 2131std::int64_t * result ) { 2132sycl::queue q = desc_ptr -> get_queue (); 2133std::uint64_t key = ::dpct::detail:: get_type_combination_id ( x_type ); 2134switch ( key ) { 2135case ::dpct::detail:: get_type_combination_id (library_data_t:: real_float ): { 2136::dpct::detail:: iamin_impl < float > ( q , n , x , incx , result ); 2137break ; 2138} 2139case ::dpct::detail:: get_type_combination_id (library_data_t:: real_double ): { 2140::dpct::detail:: iamin_impl < double > ( q , n , x , incx , result ); 2141break ; 2142} 2143case ::dpct::detail:: get_type_combination_id (library_data_t:: complex_float ): { 2144::dpct::detail:: iamin_impl < std::complex < float >> ( q , n , x , incx , result ); 2145break ; 2146} 2147case ::dpct::detail:: get_type_combination_id ( 2148library_data_t:: complex_double ): { 2149::dpct::detail:: iamin_impl < std::complex < double >> ( q , n , x , incx , result ); 2150break ; 2151} 2152default : 2153throw std:: runtime_error ( "the combination of data type is unsupported" ); 2154} 2155} 2156 2157/// Finds the index of the element with the largest absolute value in a vector. 2158/// \param [in] desc_ptr Descriptor. 2159/// \param [in] n Number of elements in vector x. 2160/// \param [in] x Input vector x. 2161/// \param [in] x_type Data type of the vector x. 2162/// \param [in] incx Stride of vector x. 2163/// \param [out] result The index of the maximal element. 2164inline void iamax (descriptor_ptr desc_ptr , std::int64_t n , const void * x , 2165library_data_t x_type , std::int64_t incx , int * result ) { 2166dpct::blas::wrapper_int_to_int64_out wrapper ( desc_ptr -> get_queue (), result ); 2167iamax ( desc_ptr , n , x , x_type , incx , wrapper . get_ptr ()); 2168} 2169 2170/// Finds the index of the element with the smallest absolute value in a vector. 2171/// \param [in] desc_ptr Descriptor. 2172/// \param [in] n Number of elements in vector x. 2173/// \param [in] x Input vector x. 2174/// \param [in] x_type Data type of the vector x. 2175/// \param [in] incx Stride of vector x. 2176/// \param [out] result The index of the minimum element. 2177inline void iamin (descriptor_ptr desc_ptr , std::int64_t n , const void * x , 2178library_data_t x_type , std::int64_t incx , int * result ) { 2179dpct::blas::wrapper_int_to_int64_out wrapper ( desc_ptr -> get_queue (), result ); 2180iamin ( desc_ptr , n , x , x_type , incx , wrapper . get_ptr ()); 2181} 2182 2183/// Finds the least squares solutions for a batch of overdetermined linear 2184/// systems. Uses the QR factorization to solve a grouped batch of linear 2185/// systems with full rank matrices. 2186/// \param [in] desc_ptr Descriptor. 2187/// \param [in] trans Operation applied to \p a. 2188/// \param [in] m The number of rows of \p a. 2189/// \param [in] n The number of columns of \p a. 2190/// \param [in] nrhs The number of columns of \p b. 2191/// \param [in, out] a Array of pointers to matrices. 2192/// \param [in] lda The leading dimension of \p a. 2193/// \param [in, out] b Array of pointers to matrices. 2194/// \param [in] ldb The leading dimension of \p b. 2195/// \param [out] info Set to 0 if no error. 2196/// \param [out] dev_info Optional. If it is not NULL : dev_info[i]==0 means the 2197/// i-th problem is successful; dev_info[i]!=0 means dev_info[i] is the first 2198/// zero diagonal element of the i-th \p a . 2199/// \param [in] batch_size The size of the batch. 2200template < typename T > 2201inline sycl::event 2202gels_batch_wrapper (descriptor_ptr desc_ptr , oneapi::mkl::transpose trans , int m , 2203int n , int nrhs , T * const a [], int lda , T * const b [], 2204int ldb , int * info , int * dev_info , int batch_size ) { 2205#if defined( DPCT_USM_LEVEL_NONE ) || !defined( __INTEL_MKL__ ) 2206#if defined( DPCT_USM_LEVEL_NONE ) 2207throw std:: runtime_error ( "this API is unsupported when USM level is none" ); 2208#else 2209throw std:: runtime_error ( "The oneAPI Math Kernel Library (oneMKL) Interfaces " 2210"Project does not support this API." ); 2211#endif 2212#else 2213using Ty = typename ::dpct::detail::lib_data_traits_t < T > ; 2214sycl::queue exec_queue = desc_ptr -> get_queue (); 2215struct matrix_info_t { 2216oneapi::mkl::transpose trans_info ; 2217std::int64_t m_info ; 2218std::int64_t n_info ; 2219std::int64_t nrhs_info ; 2220std::int64_t lda_info ; 2221std::int64_t ldb_info ; 2222std::int64_t group_size_info ; 2223}; 2224matrix_info_t * matrix_info = 2225(matrix_info_t * )std:: malloc ( sizeof ( matrix_info_t )); 2226matrix_info -> trans_info = trans ; 2227matrix_info -> m_info = m ; 2228matrix_info -> n_info = n ; 2229matrix_info -> nrhs_info = nrhs ; 2230matrix_info -> lda_info = lda ; 2231matrix_info -> ldb_info = ldb ; 2232matrix_info -> group_size_info = batch_size ; 2233std::int64_t scratchpad_size = 2234oneapi::mkl::lapack:: gels_batch_scratchpad_size < Ty > ( 2235exec_queue , & ( matrix_info -> trans_info ), & ( matrix_info -> m_info ), 2236& ( matrix_info -> n_info ), & ( matrix_info -> nrhs_info ), 2237& ( matrix_info -> lda_info ), & ( matrix_info -> ldb_info ), 1 , 2238& ( matrix_info -> group_size_info )); 2239Ty * scratchpad = sycl:: malloc_device < Ty > ( scratchpad_size , exec_queue ); 2240 2241* info = 0 ; 2242if ( dev_info ) 2243exec_queue . memset ( dev_info , 0 , batch_size * sizeof (int)); 2244static const std::vector < sycl::event > empty_events {}; 2245static const std::string api_name = "oneapi::mkl::lapack::gels_batch" ; 2246sycl::event e = ::dpct::detail:: catch_batch_error_f < sycl::event > ( 2247nullptr , api_name , exec_queue , info , dev_info , batch_size , 2248oneapi::mkl::lapack:: gels_batch , exec_queue , & ( matrix_info -> trans_info ), 2249& ( matrix_info -> m_info ), & ( matrix_info -> n_info ), & ( matrix_info -> nrhs_info ), 2250(Ty ** ) a , & ( matrix_info -> lda_info ), (Ty ** ) b , & ( matrix_info -> ldb_info ), 2251(std::int64_t) 1 , & ( matrix_info -> group_size_info ), (Ty * ) scratchpad , 2252(std::int64_t) scratchpad_size , empty_events ); 2253 2254return exec_queue . submit ([ & ](sycl::handler & cgh ) { 2255cgh . host_task ([ = ]() mutable { 2256::dpct::detail:: catch_batch_error ( 2257nullptr , api_name , exec_queue , info , dev_info , 2258matrix_info -> group_size_info , 2259[](sycl::event _e ) { 2260_e . wait_and_throw (); 2261return 0 ; 2262}, 2263e ); 2264std:: free ( matrix_info ); 2265sycl:: free ( scratchpad , exec_queue ); 2266}); 2267}); 2268#endif 2269} 2270} // namespace blas 2271 2272/// Computes matrix-matrix product with general matrices. 2273/// \param [in] q The queue where the routine should be executed. 2274/// \param [in] a_trans Specifies the operation applied to A. 2275/// \param [in] b_trans Specifies the operation applied to B. 2276/// \param [in] m Specifies the number of rows of the matrix op(A) and of the matrix C. 2277/// \param [in] n Specifies the number of columns of the matrix op(B) and of the matrix C. 2278/// \param [in] k Specifies the number of columns of the matrix op(A) and the number of rows of the matrix op(B). 2279/// \param [in] alpha Scaling factor for the matrix-matrix product. 2280/// \param [in] a Input matrix A. 2281/// \param [in] a_type Data type of the matrix A. 2282/// \param [in] lda Leading dimension of A. 2283/// \param [in] b Input matrix B. 2284/// \param [in] b_type Data type of the matrix B. 2285/// \param [in] ldb Leading dimension of B. 2286/// \param [in] beta Scaling factor for matrix C. 2287/// \param [in, out] c Input/Output matrix C. 2288/// \param [in] c_type Data type of the matrix C. 2289/// \param [in] ldc Leading dimension of C. 2290/// \param [in] scaling_type Data type of the scaling factors. 2291[[ deprecated ( "Please use dpct::blas::gemm(...) instead." )]] inline void 2292gemm (sycl::queue & q , oneapi::mkl::transpose a_trans , 2293oneapi::mkl::transpose b_trans , int m , int n , int k , const void * alpha , 2294const void * a , library_data_t a_type , int lda , const void * b , 2295library_data_t b_type , int ldb , const void * beta , void * c , 2296library_data_t c_type , int ldc , library_data_t scaling_type ) { 2297blas::descriptor desc ; 2298desc . set_queue ( & q ); 2299blas:: gemm ( & desc , a_trans , b_trans , m , n , k , alpha , a , a_type , lda , b , b_type , 2300ldb , beta , c , c_type , ldc , scaling_type ); 2301} 2302 2303/// Computes a batch of matrix-matrix product with general matrices. 2304/// \param [in] q The queue where the routine should be executed. 2305/// \param [in] a_trans Specifies the operation applied to A. 2306/// \param [in] b_trans Specifies the operation applied to B. 2307/// \param [in] m Specifies the number of rows of the matrix op(A) and of the matrix C. 2308/// \param [in] n Specifies the number of columns of the matrix op(B) and of the matrix C. 2309/// \param [in] k Specifies the number of columns of the matrix op(A) and the number of rows of the matrix op(B). 2310/// \param [in] alpha Scaling factor for the matrix-matrix product. 2311/// \param [in] a Input matrix A. 2312/// \param [in] a_type Data type of the matrix A. 2313/// \param [in] lda Leading dimension of A. 2314/// \param [in] b Input matrix B. 2315/// \param [in] b_type Data type of the matrix B. 2316/// \param [in] ldb Leading dimension of B. 2317/// \param [in] beta Scaling factor for matrix C. 2318/// \param [in, out] c Input/Output matrix C. 2319/// \param [in] c_type Data type of the matrix C. 2320/// \param [in] ldc Leading dimension of C. 2321/// \param [in] batch_size Specifies the number of matrix multiply operations to perform. 2322/// \param [in] scaling_type Data type of the scaling factors. 2323[[ deprecated ( "Please use dpct::blas::gemm_batch(...) instead." )]] inline void 2324gemm_batch (sycl::queue & q , oneapi::mkl::transpose a_trans , 2325oneapi::mkl::transpose b_trans , int m , int n , int k , 2326const void * alpha , const void * a [], library_data_t a_type , int lda , 2327const void * b [], library_data_t b_type , int ldb , const void * beta , 2328void * c [], library_data_t c_type , int ldc , int batch_size , 2329library_data_t scaling_type ) { 2330blas::descriptor desc ; 2331desc . set_queue ( & q ); 2332blas:: gemm_batch ( & desc , a_trans , b_trans , m , n , k , alpha , a , a_type , lda , b , 2333b_type , ldb , beta , c , c_type , ldc , batch_size , scaling_type ); 2334} 2335 2336/// Computes a batch of matrix-matrix product with general matrices. 2337/// \param [in] q The queue where the routine should be executed. 2338/// \param [in] a_trans Specifies the operation applied to A. 2339/// \param [in] b_trans Specifies the operation applied to B. 2340/// \param [in] m Specifies the number of rows of the matrix op(A) and of the matrix C. 2341/// \param [in] n Specifies the number of columns of the matrix op(B) and of the matrix C. 2342/// \param [in] k Specifies the number of columns of the matrix op(A) and the number of rows of the matrix op(B). 2343/// \param [in] alpha Scaling factor for the matrix-matrix product. 2344/// \param [in] a Input matrix A. 2345/// \param [in] a_type Data type of the matrix A. 2346/// \param [in] lda Leading dimension of A. 2347/// \param [in] stride_a Stride between the different A matrices. 2348/// \param [in] b Input matrix B. 2349/// \param [in] b_type Data type of the matrix B. 2350/// \param [in] ldb Leading dimension of B. 2351/// \param [in] stride_b Stride between the different B matrices. 2352/// \param [in] beta Scaling factor for matrix C. 2353/// \param [in, out] c Input/Output matrix C. 2354/// \param [in] c_type Data type of the matrix C. 2355/// \param [in] ldc Leading dimension of C. 2356/// \param [in] stride_c Stride between the different C matrices. 2357/// \param [in] batch_size Specifies the number of matrix multiply operations to perform. 2358/// \param [in] scaling_type Data type of the scaling factors. 2359[[ deprecated ( "Please use dpct::blas::gemm_batch(...) instead." )]] inline void 2360gemm_batch (sycl::queue & q , oneapi::mkl::transpose a_trans , 2361oneapi::mkl::transpose b_trans , int m , int n , int k , 2362const void * alpha , const void * a , library_data_t a_type , int lda , 2363long long int stride_a , const void * b , library_data_t b_type , 2364int ldb , long long int stride_b , const void * beta , void * c , 2365library_data_t c_type , int ldc , long long int stride_c , 2366int batch_size , library_data_t scaling_type ) { 2367blas::descriptor desc ; 2368desc . set_queue ( & q ); 2369blas:: gemm_batch ( & desc , a_trans , b_trans , m , n , k , alpha , a , a_type , lda , 2370stride_a , b , b_type , ldb , stride_b , beta , c , c_type , ldc , 2371stride_c , batch_size , scaling_type ); 2372} 2373 2374/// This routines perform a special rank-k update of a symmetric matrix C by 2375/// general matrices A and B. 2376/// \param [in] q The queue where the routine should be executed. 2377/// \param [in] uplo Specifies whether C's data is stored in its upper or lower triangle. 2378/// \param [in] trans Specifies the operation to apply. 2379/// \param [in] n The number of rows and columns in C. 2380/// \param [in] k The inner dimension of matrix multiplications. 2381/// \param [in] alpha Scaling factor for the rank-k update. 2382/// \param [in] a Input matrix A. 2383/// \param [in] lda Leading dimension of A. 2384/// \param [in] b Input matrix B. 2385/// \param [in] ldb Leading dimension of B. 2386/// \param [in] beta Scaling factor for the rank-k update. 2387/// \param [in, out] c Input/Output matrix C. 2388/// \param [in] ldc Leading dimension of C. 2389template < class T > 2390[[ deprecated ( "Please use dpct::blas::syrk(...) instead." )]] inline void 2391syrk (sycl::queue & q , oneapi::mkl::uplo uplo , oneapi::mkl::transpose trans , 2392int n , int k , const T * alpha , const T * a , int lda , const T * b , int ldb , 2393const T * beta , T * c , int ldc ) { 2394blas::descriptor desc ; 2395desc . set_queue ( & q ); 2396blas:: syrk < T > ( & desc , uplo , trans , n , k , alpha , a , lda , b , ldb , beta , c , ldc ); 2397} 2398 2399/// This routines perform a special rank-k update of a Hermitian matrix C by 2400/// general matrices A and B. 2401/// \param [in] q The queue where the routine should be executed. 2402/// \param [in] uplo Specifies whether C's data is stored in its upper or lower triangle. 2403/// \param [in] trans Specifies the operation to apply. 2404/// \param [in] n The number of rows and columns in C. 2405/// \param [in] k The inner dimension of matrix multiplications. 2406/// \param [in] alpha Scaling factor for the rank-k update. 2407/// \param [in] a Input matrix A. 2408/// \param [in] lda Leading dimension of A. 2409/// \param [in] b Input matrix B. 2410/// \param [in] ldb Leading dimension of B. 2411/// \param [in] beta Scaling factor for the rank-k update. 2412/// \param [in, out] c Input/Output matrix C. 2413/// \param [in] ldc Leading dimension of C. 2414template < class T, class Tbeta > 2415[[ deprecated ( "Please use dpct::blas::herk(...) instead." )]] inline void 2416herk (sycl::queue & q , oneapi::mkl::uplo uplo , oneapi::mkl::transpose trans , 2417int n , int k , const T * alpha , const T * a , int lda , const T * b , int ldb , 2418const Tbeta * beta , T * c , int ldc ) { 2419blas::descriptor desc ; 2420desc . set_queue ( & q ); 2421blas:: herk ( & desc , uplo , trans , n , k , alpha , a , lda , b , ldb , beta , c , ldc ); 2422} 2423 2424/// This routine performs a group of trsm operations. Each trsm solves an 2425/// equation of the form op(A) * X = alpha * B or X * op(A) = alpha * B. 2426/// \param [in] q The queue where the routine should be executed. 2427/// \param [in] left_right Specifies A multiplies X on the left or on the right. 2428/// \param [in] upper_lower Specifies A is upper or lower triangular. 2429/// \param [in] trans Specifies the operation applied to A. 2430/// \param [in] unit_diag Specifies whether A is unit triangular. 2431/// \param [in] m Number of rows of the B matrices. 2432/// \param [in] n Number of columns of the B matrices. 2433/// \param [in] alpha Scaling factor for the solutions. 2434/// \param [in] a Input matrices A. 2435/// \param [in] a_type Data type of the matrices A. 2436/// \param [in] lda Leading dimension of the matrices A. 2437/// \param [in, out] b Input and output matrices B. 2438/// \param [in] b_type Data type of the matrices B. 2439/// \param [in] ldb Leading dimension of the matrices B. 2440/// \param [in] batch_size Specifies the number of trsm operations to perform. 2441/// \param [in] scaling_type Data type of the scaling factors. 2442[[ deprecated ( "Please use dpct::blas::trsm_batch(...) instead." )]] inline void 2443trsm_batch (sycl::queue & q , oneapi::mkl::side left_right , 2444oneapi::mkl::uplo upper_lower , oneapi::mkl::transpose trans , 2445oneapi::mkl::diag unit_diag , int m , int n , const void * alpha , 2446const void ** a , library_data_t a_type , int lda , void ** b , 2447library_data_t b_type , int ldb , int batch_size , 2448library_data_t scaling_type ) { 2449blas::descriptor desc ; 2450desc . set_queue ( & q ); 2451blas:: trsm_batch ( & desc , left_right , upper_lower , trans , unit_diag , m , n , 2452alpha , a , a_type , lda , b , b_type , ldb , batch_size , 2453scaling_type ); 2454} 2455 2456/// Computes a triangular matrix-general matrix product. 2457/// \param [in] q The queue where the routine should be executed. 2458/// \param [in] left_right Specifies A is on the left or right side of the 2459/// multiplication. 2460/// \param [in] upper_lower Specifies A is upper or lower triangular. 2461/// \param [in] trans Specifies the operation applied to A. 2462/// \param [in] unit_diag Specifies whether A is unit triangular. 2463/// \param [in] m Number of rows of B. 2464/// \param [in] n Number of columns of B. 2465/// \param [in] alpha Scaling factor for the matrix-matrix product. 2466/// \param [in] a Input matrices A. 2467/// \param [in] lda Leading dimension of the matrices A. 2468/// \param [in] b Input matrices B. 2469/// \param [in] ldb Leading dimension of the matrices B. 2470/// \param [out] c Output matrices C. 2471/// \param [in] ldc Leading dimension of the matrices C. 2472template < class T > 2473[[ deprecated ( "Please use dpct::blas::trmm(...) instead." )]] inline void 2474trmm (sycl::queue & q , oneapi::mkl::side left_right , 2475oneapi::mkl::uplo upper_lower , oneapi::mkl::transpose trans , 2476oneapi::mkl::diag unit_diag , int m , int n , const T * alpha , const T * a , 2477int lda , const T * b , int ldb , T * c , int ldc ) { 2478blas::descriptor desc ; 2479desc . set_queue ( & q ); 2480blas:: trmm < T > ( & desc , left_right , upper_lower , trans , unit_diag , m , n , alpha , 2481a , lda , b , ldb , c , ldc ); 2482} 2483 2484/// Computes the Euclidean norm of a vector. 2485/// \param [in] q The queue where the routine should be executed. 2486/// \param [in] n Number of elements in vector x. 2487/// \param [in] x Input vector x. 2488/// \param [in] x_type Data type of the vector x. 2489/// \param [in] incx Stride of vector x. 2490/// \param [out] result The result scalar. 2491/// \param [in] result_type Data type of the result. 2492[[ deprecated ( "Please use dpct::blas::nrm2(...) instead." )]] inline void 2493nrm2 (sycl::queue & q , int n , const void * x , library_data_t x_type , int incx , 2494void * result , library_data_t result_type ) { 2495blas::descriptor desc ; 2496desc . set_queue ( & q ); 2497blas:: nrm2 ( & desc , n , x , x_type , incx , result , result_type ); 2498} 2499 2500/// Computes the dot product of two vectors. 2501/// \param [in] q The queue where the routine should be executed. 2502/// \param [in] n Number of elements in vector x. 2503/// \param [in] x Input vector x. 2504/// \param [in] x_type Data type of the vector x. 2505/// \param [in] incx Stride of vector x. 2506/// \param [in] y Input vector y. 2507/// \param [in] y_type Data type of the vector y. 2508/// \param [in] incy Stride of vector y. 2509/// \param [out] result The result scalar. 2510/// \param [in] result_type Data type of the result. 2511[[ deprecated ( "Please use dpct::blas::dot(...) instead." )]] inline void 2512dot (sycl::queue & q , int n , const void * x , library_data_t x_type , int incx , 2513const void * y , library_data_t y_type , int incy , void * result , 2514library_data_t result_type ) { 2515blas::descriptor desc ; 2516desc . set_queue ( & q ); 2517blas:: dot ( & desc , n , x , x_type , incx , y , y_type , incy , result , result_type ); 2518} 2519 2520/// Computes the dot product of two vectors, conjugating the first vector. 2521/// \param [in] q The queue where the routine should be executed. 2522/// \param [in] n Number of elements in vector x. 2523/// \param [in] x Input vector x. 2524/// \param [in] x_type Data type of the vector x. 2525/// \param [in] incx Stride of vector x. 2526/// \param [in] y Input vector y. 2527/// \param [in] y_type Data type of the vector y. 2528/// \param [in] incy Stride of vector y. 2529/// \param [out] result The result scalar. 2530/// \param [in] result_type Data type of the result. 2531[[ deprecated ( "Please use dpct::blas::dotc(...) instead." )]] inline void 2532dotc (sycl::queue & q , int n , const void * x , library_data_t x_type , int incx , 2533const void * y , library_data_t y_type , int incy , void * result , 2534library_data_t result_type ) { 2535blas::descriptor desc ; 2536desc . set_queue ( & q ); 2537blas:: dotc ( & desc , n , x , x_type , incx , y , y_type , incy , result , result_type ); 2538} 2539 2540/// Computes the product of a vector by a scalar. 2541/// \param [in] q The queue where the routine should be executed. 2542/// \param [in] n Number of elements in vector x. 2543/// \param [in] alpha The scale factor alpha. 2544/// \param [in] alpha_type The data type of alpha. 2545/// \param [in, out] x Input/Output vector x. 2546/// \param [in] x_type Data type of the vector x. 2547/// \param [in] incx Stride of vector x. 2548[[ deprecated ( "Please use dpct::blas::scal(...) instead." )]] inline void 2549scal (sycl::queue & q , int n , const void * alpha , library_data_t alpha_type , 2550void * x , library_data_t x_type , int incx ) { 2551blas::descriptor desc ; 2552desc . set_queue ( & q ); 2553blas:: scal ( & desc , n , alpha , alpha_type , x , x_type , incx ); 2554} 2555 2556/// Computes a vector-scalar product and adds the result to a vector. 2557/// \param [in] q The queue where the routine should be executed. 2558/// \param [in] n Number of elements in vector x. 2559/// \param [in] alpha The scale factor alpha. 2560/// \param [in] alpha_type The data type of alpha. 2561/// \param [in] x Input vector x. 2562/// \param [in] x_type Data type of the vector x. 2563/// \param [in] incx Stride of vector x. 2564/// \param [in, out] y Input/Output vector y. 2565/// \param [in] y_type Data type of the vector y. 2566/// \param [in] incy Stride of vector y. 2567[[ deprecated ( "Please use dpct::blas::axpy(...) instead." )]] inline void 2568axpy (sycl::queue & q , int n , const void * alpha , library_data_t alpha_type , 2569const void * x , library_data_t x_type , int incx , void * y , 2570library_data_t y_type , int incy ) { 2571blas::descriptor desc ; 2572desc . set_queue ( & q ); 2573blas:: axpy ( & desc , n , alpha , alpha_type , x , x_type , incx , y , y_type , incy ); 2574} 2575 2576/// Performs rotation of points in the plane. 2577/// \param [in] q The queue where the routine should be executed. 2578/// \param [in] n Number of elements in vector x. 2579/// \param [in, out] x Input/Output vector x. 2580/// \param [in] x_type Data type of the vector x. 2581/// \param [in] incx Stride of vector x. 2582/// \param [in, out] y Input/Output vector y. 2583/// \param [in] y_type Data type of the vector y. 2584/// \param [in] incy Stride of vector y. 2585/// \param [in] c Scaling factor. 2586/// \param [in] s Scaling factor. 2587/// \param [in] cs_type Data type of the scaling factors. 2588[[ deprecated ( "Please use dpct::blas::rot(...) instead." )]] inline void 2589rot (sycl::queue & q , int n , void * x , library_data_t x_type , int incx , void * y , 2590library_data_t y_type , int incy , const void * c , const void * s , 2591library_data_t cs_type ) { 2592blas::descriptor desc ; 2593desc . set_queue ( & q ); 2594blas:: rot ( & desc , n , x , x_type , incx , y , y_type , incy , c , s , cs_type ); 2595} 2596} // namespace dpct 2597#undef DPCT_COMPUTE_MODE_ARG 2598#undef DPCT_COMPUTE_MODE_PARAM 2599#endif // __DPCT_BLAS_UTILS_HPP__