All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
blas1_host.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"
// IxAMAX
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostiSamax(ViennaCLBackend /*backend*/, ViennaCLInt n,
ViennaCLInt *index,
float *x, ViennaCLInt offx, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
*index = static_cast<ViennaCLInt>(viennacl::linalg::index_norm_inf(v1));
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostiDamax(ViennaCLBackend /*backend*/, ViennaCLInt n,
ViennaCLInt *index,
double *x, ViennaCLInt offx, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
*index = static_cast<ViennaCLInt>(viennacl::linalg::index_norm_inf(v1));
return ViennaCLSuccess;
}
// xASUM
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSasum(ViennaCLBackend /*backend*/, ViennaCLInt n,
float *alpha,
float *x, ViennaCLInt offx, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
*alpha = viennacl::linalg::norm_1(v1);
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDasum(ViennaCLBackend /*backend*/, ViennaCLInt n,
double *alpha,
double *x, ViennaCLInt offx, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
*alpha = viennacl::linalg::norm_1(v1);
return ViennaCLSuccess;
}
// xAXPY
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSaxpy(ViennaCLBackend /*backend*/, ViennaCLInt n,
float alpha,
float *x, ViennaCLInt offx, int incx,
float *y, ViennaCLInt offy, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
viennacl::vector_base<float> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
v2 += alpha * v1;
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDaxpy(ViennaCLBackend /*backend*/, ViennaCLInt n,
double alpha,
double *x, ViennaCLInt offx, int incx,
double *y, ViennaCLInt offy, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
viennacl::vector_base<double> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
v2 += alpha * v1;
return ViennaCLSuccess;
}
// xCOPY
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostScopy(ViennaCLBackend /*backend*/, ViennaCLInt n,
float *x, ViennaCLInt offx, int incx,
float *y, ViennaCLInt offy, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
viennacl::vector_base<float> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
v2 = v1;
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDcopy(ViennaCLBackend /*backend*/, ViennaCLInt n,
double *x, ViennaCLInt offx, int incx,
double *y, ViennaCLInt offy, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
viennacl::vector_base<double> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
v2 = v1;
return ViennaCLSuccess;
}
// xAXPY
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSdot(ViennaCLBackend /*backend*/, ViennaCLInt n,
float *alpha,
float *x, ViennaCLInt offx, int incx,
float *y, ViennaCLInt offy, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
viennacl::vector_base<float> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
*alpha = viennacl::linalg::inner_prod(v1, v2);
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDdot(ViennaCLBackend /*backend*/, ViennaCLInt n,
double *alpha,
double *x, ViennaCLInt offx, int incx,
double *y, ViennaCLInt offy, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
viennacl::vector_base<double> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
*alpha = viennacl::linalg::inner_prod(v1, v2);
return ViennaCLSuccess;
}
// xNRM2
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSnrm2(ViennaCLBackend /*backend*/, ViennaCLInt n,
float *alpha,
float *x, ViennaCLInt offx, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
*alpha = viennacl::linalg::norm_2(v1);
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDnrm2(ViennaCLBackend /*backend*/, ViennaCLInt n,
double *alpha,
double *x, ViennaCLInt offx, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
*alpha = viennacl::linalg::norm_2(v1);
return ViennaCLSuccess;
}
// xROT
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSrot(ViennaCLBackend /*backend*/, ViennaCLInt n,
float *x, ViennaCLInt offx, int incx,
float *y, ViennaCLInt offy, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
viennacl::vector_base<float> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
viennacl::linalg::plane_rotation(v1, v2, c, s);
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDrot(ViennaCLBackend /*backend*/, ViennaCLInt n,
double *x, ViennaCLInt offx, int incx,
double *y, ViennaCLInt offy, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
viennacl::vector_base<double> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
viennacl::linalg::plane_rotation(v1, v2, c, s);
return ViennaCLSuccess;
}
// xSCAL
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSscal(ViennaCLBackend /*backend*/, ViennaCLInt n,
float alpha,
float *x, ViennaCLInt offx, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
v1 *= alpha;
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDscal(ViennaCLBackend /*backend*/, ViennaCLInt n,
double alpha,
double *x, ViennaCLInt offx, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
v1 *= alpha;
return ViennaCLSuccess;
}
// xSWAP
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSswap(ViennaCLBackend /*backend*/, ViennaCLInt n,
float *x, ViennaCLInt offx, int incx,
float *y, ViennaCLInt offy, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
viennacl::vector_base<float> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
viennacl::swap(v1, v2);
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDswap(ViennaCLBackend /*backend*/, ViennaCLInt n,
double *x, ViennaCLInt offx, int incx,
double *y, ViennaCLInt offy, int 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, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
viennacl::vector_base<double> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
viennacl::swap(v1, v2);
return ViennaCLSuccess;
}
ViennaCLHostDnrm2
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDnrm2(ViennaCLBackend, ViennaCLInt n, double *alpha, double *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:196
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
ViennaCLHostSasum
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSasum(ViennaCLBackend, ViennaCLInt n, float *alpha, float *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:67
ViennaCLHostSrot
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSrot(ViennaCLBackend, ViennaCLInt n, float *x, ViennaCLInt offx, int incx, float *y, ViennaCLInt offy, int incy, float c, float s)
Definition: blas1_host.cpp:211
ViennaCLHostScopy
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostScopy(ViennaCLBackend, ViennaCLInt n, float *x, ViennaCLInt offx, int incx, float *y, ViennaCLInt offy, int incy)
Definition: blas1_host.cpp:126
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
ViennaCLHostSaxpy
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSaxpy(ViennaCLBackend, ViennaCLInt n, float alpha, float *x, ViennaCLInt offx, int incx, float *y, ViennaCLInt offy, int incy)
Definition: blas1_host.cpp:95
ViennaCLHostSnrm2
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSnrm2(ViennaCLBackend, ViennaCLInt n, float *alpha, float *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:184
ViennaCLHostiDamax
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostiDamax(ViennaCLBackend, ViennaCLInt n, ViennaCLInt *index, double *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:51
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
ViennaCLHostDdot
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDdot(ViennaCLBackend, ViennaCLInt n, double *alpha, double *x, ViennaCLInt offx, int incx, double *y, ViennaCLInt offy, int incy)
Definition: blas1_host.cpp:168
viennacl_private.hpp
ViennaCLHostDrot
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDrot(ViennaCLBackend, ViennaCLInt n, double *x, ViennaCLInt offx, int incx, double *y, ViennaCLInt offy, int incy, double c, double s)
Definition: blas1_host.cpp:225
ViennaCLHostSdot
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSdot(ViennaCLBackend, ViennaCLInt n, float *alpha, float *x, ViennaCLInt offx, int incx, float *y, ViennaCLInt offy, int incy)
Definition: blas1_host.cpp:154
viennacl::vector_base< float >
ViennaCLInt
int ViennaCLInt
Definition: viennacl.hpp:48
ViennaCLHostSswap
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSswap(ViennaCLBackend, ViennaCLInt n, float *x, ViennaCLInt offx, int incx, float *y, ViennaCLInt offy, int incy)
Definition: blas1_host.cpp:269
viennacl::MAIN_MEMORY
Definition: forwards.h:348
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 ...
ViennaCLHostDswap
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDswap(ViennaCLBackend, ViennaCLInt n, double *x, ViennaCLInt offx, int incx, double *y, ViennaCLInt offy, int incy)
Definition: blas1_host.cpp:282
ViennaCLHostDasum
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDasum(ViennaCLBackend, ViennaCLInt n, double *alpha, double *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:79
viennacl::linalg::norm_1
T norm_1(std::vector< T, A > const &v1)
Definition: norm_1.hpp:61
ViennaCLHostDaxpy
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDaxpy(ViennaCLBackend, ViennaCLInt n, double alpha, double *x, ViennaCLInt offx, int incx, double *y, ViennaCLInt offy, int incy)
Definition: blas1_host.cpp:109
ViennaCLHostiSamax
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostiSamax(ViennaCLBackend, ViennaCLInt n, ViennaCLInt *index, float *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:39
ViennaCLHostSscal
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSscal(ViennaCLBackend, ViennaCLInt n, float alpha, float *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:243
scalar.hpp
Implementation of the ViennaCL scalar class.
ViennaCLHostDcopy
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDcopy(ViennaCLBackend, ViennaCLInt n, double *x, ViennaCLInt offx, int incx, double *y, ViennaCLInt offy, int incy)
Definition: blas1_host.cpp:139
viennacl.hpp
norm_inf.hpp
Generic interface for the l^infty-norm. See viennacl/linalg/vector_operations.hpp for implementations...
ViennaCLHostDscal
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDscal(ViennaCLBackend, ViennaCLInt n, double alpha, double *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:255
ViennaCLSuccess
Definition: viennacl.hpp:99
viennacl::vector_base::size_type
SizeT size_type
Definition: vector_def.hpp:112