All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
blas3_opencl.cpp
Go to the documentation of this file.
/* =========================================================================
Copyright (c) 2010-2014, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
-----------------
ViennaCL - The Vienna Computing Library
-----------------
Project Head: Karl Rupp rupp@iue.tuwien.ac.at
(A list of authors and contributors can be found in the PDF manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
// include necessary system headers
#include <iostream>
#include "viennacl.hpp"
#include "viennacl_private.hpp"
#include "blas3.hpp"
//include basic scalar and vector types of ViennaCL
#include "viennacl/scalar.hpp"
#include "viennacl/vector.hpp"
#include "viennacl/matrix.hpp"
#include "viennacl/linalg/direct_solve.hpp"
#include "viennacl/linalg/prod.hpp"
#ifdef VIENNACL_WITH_OPENCL
//
// xGEMV
//
namespace detail
{
template <typename NumericT>
ViennaCLStatus ViennaCLOpenCLgemm_impl(ViennaCLBackend backend,
ViennaCLOrder orderA, ViennaCLTranspose transA,
ViennaCLOrder orderB, ViennaCLTranspose transB,
ViennaCLOrder orderC,
ViennaCLInt m, ViennaCLInt n, ViennaCLInt k,
NumericT alpha,
cl_mem A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda,
cl_mem B, ViennaCLInt offB_row, ViennaCLInt offB_col, ViennaCLInt incB_row, ViennaCLInt incB_col, ViennaCLInt ldb,
NumericT beta,
cl_mem C, ViennaCLInt offC_row, ViennaCLInt offC_col, ViennaCLInt incC_row, ViennaCLInt incC_col, ViennaCLInt ldc)
{
typedef typename viennacl::matrix_base<NumericT>::size_type size_type;
typedef typename viennacl::matrix_base<NumericT>::size_type difference_type;
size_type A_size1 = static_cast<size_type>((transA == ViennaCLTrans) ? k : m);
size_type A_size2 = static_cast<size_type>((transA == ViennaCLTrans) ? m : k);
size_type B_size1 = static_cast<size_type>((transB == ViennaCLTrans) ? n : k);
size_type B_size2 = static_cast<size_type>((transB == ViennaCLTrans) ? k : n);
bool A_row_major = (orderA == ViennaCLRowMajor);
bool B_row_major = (orderB == ViennaCLRowMajor);
bool C_row_major = (orderC == ViennaCLRowMajor);
viennacl::matrix_base<NumericT> matA(A, viennacl::ocl::get_context(backend->opencl_backend.context_id),
A_size1, size_type(offA_row), difference_type(incA_row), size_type(A_row_major ? m : lda),
A_size2, size_type(offA_col), difference_type(incA_col), size_type(A_row_major ? lda : k), A_row_major);
viennacl::matrix_base<NumericT> matB(B, viennacl::ocl::get_context(backend->opencl_backend.context_id),
B_size1, size_type(offB_row), difference_type(incB_row), size_type(B_row_major ? k : ldb),
B_size2, size_type(offB_col), difference_type(incB_col), size_type(B_row_major ? ldb : n), B_row_major);
viennacl::matrix_base<NumericT> matC(C, viennacl::ocl::get_context(backend->opencl_backend.context_id),
size_type(m), size_type(offC_row), difference_type(incC_row), size_type(C_row_major ? m : ldc),
size_type(n), size_type(offC_col), difference_type(incC_col), size_type(C_row_major ? ldc : n), C_row_major);
detail::gemm_dispatch(alpha, matA, transA, matB, transB, beta, matC);
return ViennaCLSuccess;
}
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLSgemm(ViennaCLBackend backend,
ViennaCLOrder orderA, ViennaCLTranspose transA,
ViennaCLOrder orderB, ViennaCLTranspose transB,
ViennaCLOrder orderC,
ViennaCLInt m, ViennaCLInt n, ViennaCLInt k,
float alpha,
cl_mem A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda,
cl_mem B, ViennaCLInt offB_row, ViennaCLInt offB_col, ViennaCLInt incB_row, ViennaCLInt incB_col, ViennaCLInt ldb,
float beta,
cl_mem C, ViennaCLInt offC_row, ViennaCLInt offC_col, ViennaCLInt incC_row, ViennaCLInt incC_col, ViennaCLInt ldc)
{
return detail::ViennaCLOpenCLgemm_impl<float>(backend,
orderA, transA,
orderB, transB,
orderC,
m, n, k,
alpha,
A, offA_row, offA_col, incA_row, incA_col, lda,
B, offB_row, offB_col, incB_row, incB_col, ldb,
beta,
C, offC_row, offC_col, incC_row, incC_col, ldc);
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLDgemm(ViennaCLBackend backend,
ViennaCLOrder orderA, ViennaCLTranspose transA,
ViennaCLOrder orderB, ViennaCLTranspose transB,
ViennaCLOrder orderC,
ViennaCLInt m, ViennaCLInt n, ViennaCLInt k,
double alpha,
cl_mem A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda,
cl_mem B, ViennaCLInt offB_row, ViennaCLInt offB_col, ViennaCLInt incB_row, ViennaCLInt incB_col, ViennaCLInt ldb,
double beta,
cl_mem C, ViennaCLInt offC_row, ViennaCLInt offC_col, ViennaCLInt incC_row, ViennaCLInt incC_col, ViennaCLInt ldc)
{
return detail::ViennaCLOpenCLgemm_impl<double>(backend,
orderA, transA,
orderB, transB,
orderC,
m, n, k,
alpha,
A, offA_row, offA_col, incA_row, incA_col, lda,
B, offB_row, offB_col, incB_row, incB_col, ldb,
beta,
C, offC_row, offC_col, incC_row, incC_col, ldc);
}
#endif
ViennaCLTranspose
ViennaCLTranspose
Definition: viennacl.hpp:68
viennacl::matrix_base::size_type
SizeT size_type
Definition: matrix_def.hpp:112
ViennaCLBackend_impl
Generic backend for CUDA, OpenCL, host-based stuff.
Definition: viennacl_private.hpp:54
detail::gemm_dispatch
void gemm_dispatch(ScalarType alpha, MatrixTypeA const &A, ViennaCLTranspose transA, MatrixTypeB const &B, ViennaCLTranspose transB, ScalarType beta, MatrixTypeC &C)
Definition: blas3.hpp:39
prod.hpp
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
matrix.hpp
Implementation of the dense matrix class.
viennacl::matrix_base< NumericT >
ViennaCLStatus
ViennaCLStatus
Definition: viennacl.hpp:97
VIENNACL_EXPORTED_FUNCTION
#define VIENNACL_EXPORTED_FUNCTION
Definition: viennacl.hpp:40
NumericT
float NumericT
Definition: bisect.cpp:40
ViennaCLOpenCLBackend_impl::context_id
ViennaCLInt context_id
Definition: viennacl_private.hpp:44
viennacl_private.hpp
ViennaCLBackend_impl::opencl_backend
ViennaCLOpenCLBackend_impl opencl_backend
Definition: viennacl_private.hpp:59
ViennaCLOrder
ViennaCLOrder
Definition: viennacl.hpp:61
ViennaCLInt
int ViennaCLInt
Definition: viennacl.hpp:48
direct_solve.hpp
Implementations of dense direct solvers are found here.
vector.hpp
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
ViennaCLRowMajor
Definition: viennacl.hpp:64
blas3.hpp
ViennaCLTrans
Definition: viennacl.hpp:72
viennacl::ocl::get_context
viennacl::ocl::context & get_context(long i)
Convenience function for returning the current context.
Definition: backend.hpp:225
scalar.hpp
Implementation of the ViennaCL scalar class.
viennacl.hpp
ViennaCLSuccess
Definition: viennacl.hpp:99