All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
blas1_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 basic scalar and vector types of ViennaCL
#include "viennacl/scalar.hpp"
#include "viennacl/vector.hpp"
//include the generic inner product functions of ViennaCL
#include "viennacl/linalg/inner_prod.hpp"
//include the generic norm functions of ViennaCL
#include "viennacl/linalg/norm_1.hpp"
#include "viennacl/linalg/norm_2.hpp"
#include "viennacl/linalg/norm_inf.hpp"
#ifdef VIENNACL_WITH_OPENCL
// IxAMAX
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLiSamax(ViennaCLBackend backend, ViennaCLInt n,
ViennaCLInt *index,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx)
{
typedef viennacl::vector_base<float>::size_type size_type;
typedef viennacl::vector_base<float>::size_type difference_type;
viennacl::vector_base<float> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
*index = static_cast<ViennaCLInt>(viennacl::linalg::index_norm_inf(v1));
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLiDamax(ViennaCLBackend backend, ViennaCLInt n,
ViennaCLInt *index,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx)
{
typedef viennacl::vector_base<double>::size_type size_type;
typedef viennacl::vector_base<double>::size_type difference_type;
viennacl::vector_base<double> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
*index = static_cast<ViennaCLInt>(viennacl::linalg::index_norm_inf(v1));
return ViennaCLSuccess;
}
// xASUM
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLSasum(ViennaCLBackend backend, ViennaCLInt n,
float *alpha,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx)
{
typedef viennacl::vector_base<float>::size_type size_type;
typedef viennacl::vector_base<float>::size_type difference_type;
viennacl::vector_base<float> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
*alpha = viennacl::linalg::norm_1(v1);
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLDasum(ViennaCLBackend backend, ViennaCLInt n,
double *alpha,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx)
{
typedef viennacl::vector_base<double>::size_type size_type;
typedef viennacl::vector_base<double>::size_type difference_type;
viennacl::vector_base<double> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
*alpha = viennacl::linalg::norm_1(v1);
return ViennaCLSuccess;
}
// xAXPY
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLSaxpy(ViennaCLBackend backend, ViennaCLInt n,
float alpha,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx,
cl_mem y, ViennaCLInt offy, ViennaCLInt incy)
{
typedef viennacl::vector_base<float>::size_type size_type;
typedef viennacl::vector_base<float>::size_type difference_type;
viennacl::vector_base<float> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
viennacl::vector_base<float> v2(y, size_type(n), size_type(offy), difference_type(incy), viennacl::ocl::get_context(backend->opencl_backend.context_id));
v2 += alpha * v1;
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLDaxpy(ViennaCLBackend backend, ViennaCLInt n,
double alpha,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx,
cl_mem y, ViennaCLInt offy, ViennaCLInt incy)
{
typedef viennacl::vector_base<double>::size_type size_type;
typedef viennacl::vector_base<double>::size_type difference_type;
viennacl::vector_base<double> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
viennacl::vector_base<double> v2(y, size_type(n), size_type(offy), difference_type(incy), viennacl::ocl::get_context(backend->opencl_backend.context_id));
v2 += alpha * v1;
return ViennaCLSuccess;
}
// xCOPY
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLScopy(ViennaCLBackend backend, ViennaCLInt n,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx,
cl_mem y, ViennaCLInt offy, ViennaCLInt incy)
{
typedef viennacl::vector_base<float>::size_type size_type;
typedef viennacl::vector_base<float>::size_type difference_type;
viennacl::vector_base<float> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
viennacl::vector_base<float> v2(y, size_type(n), size_type(offy), difference_type(incy), viennacl::ocl::get_context(backend->opencl_backend.context_id));
v2 = v1;
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLDcopy(ViennaCLBackend backend, ViennaCLInt n,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx,
cl_mem y, ViennaCLInt offy, ViennaCLInt incy)
{
typedef viennacl::vector_base<double>::size_type size_type;
typedef viennacl::vector_base<double>::size_type difference_type;
viennacl::vector_base<double> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
viennacl::vector_base<double> v2(y, size_type(n), size_type(offy), difference_type(incy), viennacl::ocl::get_context(backend->opencl_backend.context_id));
v2 = v1;
return ViennaCLSuccess;
}
// xDOT
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLSdot(ViennaCLBackend backend, ViennaCLInt n,
float *alpha,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx,
cl_mem y, ViennaCLInt offy, ViennaCLInt incy)
{
typedef viennacl::vector_base<float>::size_type size_type;
typedef viennacl::vector_base<float>::size_type difference_type;
viennacl::vector_base<float> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
viennacl::vector_base<float> v2(y, size_type(n), size_type(offy), difference_type(incy), viennacl::ocl::get_context(backend->opencl_backend.context_id));
*alpha = viennacl::linalg::inner_prod(v1, v2);
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLDdot(ViennaCLBackend backend, ViennaCLInt n,
double *alpha,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx,
cl_mem y, ViennaCLInt offy, ViennaCLInt incy)
{
typedef viennacl::vector_base<double>::size_type size_type;
typedef viennacl::vector_base<double>::size_type difference_type;
viennacl::vector_base<double> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
viennacl::vector_base<double> v2(y, size_type(n), size_type(offy), difference_type(incy), viennacl::ocl::get_context(backend->opencl_backend.context_id));
*alpha = viennacl::linalg::inner_prod(v1, v2);
return ViennaCLSuccess;
}
// xNRM2
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLSnrm2(ViennaCLBackend backend, ViennaCLInt n,
float *alpha,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx)
{
typedef viennacl::vector_base<float>::size_type size_type;
typedef viennacl::vector_base<float>::size_type difference_type;
viennacl::vector_base<float> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
*alpha = viennacl::linalg::norm_2(v1);
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLDnrm2(ViennaCLBackend backend, ViennaCLInt n,
double *alpha,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx)
{
typedef viennacl::vector_base<double>::size_type size_type;
typedef viennacl::vector_base<double>::size_type difference_type;
viennacl::vector_base<double> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
*alpha = viennacl::linalg::norm_2(v1);
return ViennaCLSuccess;
}
// xROT
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLSrot(ViennaCLBackend backend, ViennaCLInt n,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx,
cl_mem y, ViennaCLInt offy, ViennaCLInt incy,
float c, float s)
{
typedef viennacl::vector_base<float>::size_type size_type;
typedef viennacl::vector_base<float>::size_type difference_type;
viennacl::vector_base<float> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
viennacl::vector_base<float> v2(y, size_type(n), size_type(offy), difference_type(incy), viennacl::ocl::get_context(backend->opencl_backend.context_id));
viennacl::linalg::plane_rotation(v1, v2, c, s);
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLDrot(ViennaCLBackend backend, ViennaCLInt n,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx,
cl_mem y, ViennaCLInt offy, ViennaCLInt incy,
double c, double s)
{
typedef viennacl::vector_base<double>::size_type size_type;
typedef viennacl::vector_base<double>::size_type difference_type;
viennacl::vector_base<double> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
viennacl::vector_base<double> v2(y, size_type(n), size_type(offy), difference_type(incy), viennacl::ocl::get_context(backend->opencl_backend.context_id));
viennacl::linalg::plane_rotation(v1, v2, c, s);
return ViennaCLSuccess;
}
// xSCAL
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLSscal(ViennaCLBackend backend, ViennaCLInt n,
float alpha,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx)
{
typedef viennacl::vector_base<float>::size_type size_type;
typedef viennacl::vector_base<float>::size_type difference_type;
viennacl::vector_base<float> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
v1 *= alpha;
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLDscal(ViennaCLBackend backend, ViennaCLInt n,
double alpha,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx)
{
typedef viennacl::vector_base<double>::size_type size_type;
typedef viennacl::vector_base<double>::size_type difference_type;
viennacl::vector_base<double> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
v1 *= alpha;
return ViennaCLSuccess;
}
// xSWAP
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLSswap(ViennaCLBackend backend, ViennaCLInt n,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx,
cl_mem y, ViennaCLInt offy, ViennaCLInt incy)
{
typedef viennacl::vector_base<float>::size_type size_type;
typedef viennacl::vector_base<float>::size_type difference_type;
viennacl::vector_base<float> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
viennacl::vector_base<float> v2(y, size_type(n), size_type(offy), difference_type(incy), viennacl::ocl::get_context(backend->opencl_backend.context_id));
viennacl::swap(v1, v2);
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLDswap(ViennaCLBackend backend, ViennaCLInt n,
cl_mem x, ViennaCLInt offx, ViennaCLInt incx,
cl_mem y, ViennaCLInt offy, ViennaCLInt incy)
{
typedef viennacl::vector_base<double>::size_type size_type;
typedef viennacl::vector_base<double>::size_type difference_type;
viennacl::vector_base<double> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
viennacl::vector_base<double> v2(y, size_type(n), size_type(offy), difference_type(incy), viennacl::ocl::get_context(backend->opencl_backend.context_id));
viennacl::swap(v1, v2);
return ViennaCLSuccess;
}
#endif
viennacl::linalg::norm_2
T norm_2(std::vector< T, A > const &v1)
Definition: norm_2.hpp:96
viennacl::linalg::index_norm_inf
vcl_size_t index_norm_inf(vector_base< T > const &vec)
Computes the index of the first entry that is equal to the supremum-norm in modulus.
Definition: vector_operations.hpp:845
norm_2.hpp
Generic interface for the l^2-norm. See viennacl/linalg/vector_operations.hpp for implementations...
ViennaCLBackend_impl
Generic backend for CUDA, OpenCL, host-based stuff.
Definition: viennacl_private.hpp:54
viennacl::linalg::plane_rotation
void plane_rotation(vector_base< T > &vec1, vector_base< T > &vec2, T alpha, T beta)
Computes a plane rotation of two vectors.
Definition: vector_operations.hpp:1152
viennacl::linalg::inner_prod
viennacl::enable_if< viennacl::is_stl< typename viennacl::traits::tag_of< VectorT1 >::type >::value, typename VectorT1::value_type >::type inner_prod(VectorT1 const &v1, VectorT2 const &v2)
Definition: inner_prod.hpp:100
ViennaCLStatus
ViennaCLStatus
Definition: viennacl.hpp:97
inner_prod.hpp
Generic interface for the computation of inner products. See viennacl/linalg/vector_operations.hpp for implementations.
norm_1.hpp
Generic interface for the l^1-norm. See viennacl/linalg/vector_operations.hpp for implementations...
viennacl::swap
void swap(vector_base< T > &vec1, vector_base< T > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector.hpp:1648
VIENNACL_EXPORTED_FUNCTION
#define VIENNACL_EXPORTED_FUNCTION
Definition: viennacl.hpp:40
v1
viennacl::vector< float > v1
Definition: global_variables.cpp:60
ViennaCLOpenCLBackend_impl::context_id
ViennaCLInt context_id
Definition: viennacl_private.hpp:44
viennacl_private.hpp
ViennaCLMatrix_impl::backend
ViennaCLBackend backend
Definition: viennacl_private.hpp:115
ViennaCLBackend_impl::opencl_backend
ViennaCLOpenCLBackend_impl opencl_backend
Definition: viennacl_private.hpp:59
viennacl::vector_base< float >
ViennaCLInt
int ViennaCLInt
Definition: viennacl.hpp:48
v2
viennacl::vector< int > v2
Definition: global_variables.cpp:61
vector.hpp
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
viennacl::linalg::norm_1
T norm_1(std::vector< T, A > const &v1)
Definition: norm_1.hpp:61
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
norm_inf.hpp
Generic interface for the l^infty-norm. See viennacl/linalg/vector_operations.hpp for implementations...
ViennaCLSuccess
Definition: viennacl.hpp:99
viennacl::vector_base::size_type
SizeT size_type
Definition: vector_def.hpp:112