All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
libviennacl.cpp
Go to the documentation of this file.
/* =========================================================================
Copyright (c) 2010-2016, 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 <vector>
// Some helper functions for this tutorial:
#include "viennacl.hpp"
#include "viennacl/vector.hpp"
int main()
{
std::size_t size = 10;
ViennaCLInt half_size = static_cast<ViennaCLInt>(size / 2);
ViennaCLBackend my_backend;
ViennaCLBackendCreate(&my_backend);
viennacl::vector<float> host_x = viennacl::scalar_vector<float>(size, 1.0, viennacl::context(viennacl::MAIN_MEMORY));
viennacl::vector<float> host_y = viennacl::scalar_vector<float>(size, 2.0, viennacl::context(viennacl::MAIN_MEMORY));
ViennaCLHostSswap(my_backend, half_size,
viennacl::linalg::host_based::detail::extract_raw_pointer<float>(host_x), 1, 2,
viennacl::linalg::host_based::detail::extract_raw_pointer<float>(host_y), 0, 2);
std::cout << " --- Host ---" << std::endl;
std::cout << "host_x: " << host_x << std::endl;
std::cout << "host_y: " << host_y << std::endl;
#ifdef VIENNACL_WITH_CUDA
viennacl::vector<float> cuda_x = viennacl::scalar_vector<float>(size, 1.0, viennacl::context(viennacl::CUDA_MEMORY));
viennacl::vector<float> cuda_y = viennacl::scalar_vector<float>(size, 2.0, viennacl::context(viennacl::CUDA_MEMORY));
ViennaCLCUDASswap(my_backend, half_size,
viennacl::cuda_arg(cuda_x), 0, 2,
viennacl::cuda_arg(cuda_y), 1, 2);
std::cout << " --- CUDA ---" << std::endl;
std::cout << "cuda_x: " << cuda_x << std::endl;
std::cout << "cuda_y: " << cuda_y << std::endl;
#endif
#ifdef VIENNACL_WITH_OPENCL
long context_id = 0;
viennacl::vector<float> opencl_x = viennacl::scalar_vector<float>(size, 1.0, viennacl::context(viennacl::ocl::get_context(context_id)));
viennacl::vector<float> opencl_y = viennacl::scalar_vector<float>(size, 2.0, viennacl::context(viennacl::ocl::get_context(context_id)));
ViennaCLBackendSetOpenCLContextID(my_backend, static_cast<ViennaCLInt>(context_id));
ViennaCLOpenCLSswap(my_backend, half_size,
viennacl::traits::opencl_handle(opencl_x).get(), 1, 2,
viennacl::traits::opencl_handle(opencl_y).get(), 1, 2);
std::cout << " --- OpenCL ---" << std::endl;
std::cout << "opencl_x: " << opencl_x << std::endl;
std::cout << "opencl_y: " << opencl_y << std::endl;
#endif
ViennaCLBackendDestroy(&my_backend);
std::cout << "!!!! TUTORIAL COMPLETED SUCCESSFULLY !!!!" << std::endl;
return EXIT_SUCCESS;
}
ViennaCLBackendCreate
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLBackendCreate(ViennaCLBackend *backend)
Definition: backend.cpp:25
ViennaCLBackend_impl
Generic backend for CUDA, OpenCL, host-based stuff.
Definition: viennacl_private.hpp:54
main
int main()
Definition: bisect.cpp:91
ViennaCLBackendSetOpenCLContextID
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLBackendSetOpenCLContextID(ViennaCLBackend backend, ViennaCLInt context_id)
Definition: backend.cpp:32
ViennaCLHostSswap
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSswap(ViennaCLBackend backend, ViennaCLInt n, float *x, ViennaCLInt offx, ViennaCLInt incx, float *y, ViennaCLInt offy, ViennaCLInt incy)
Definition: blas1_host.cpp:269
viennacl::traits::size
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:239
viennacl::CUDA_MEMORY
Definition: forwards.h:350
ViennaCLBackendDestroy
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLBackendDestroy(ViennaCLBackend *backend)
Definition: backend.cpp:39
ViennaCLCUDASswap
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLCUDASswap(ViennaCLBackend backend, ViennaCLInt n, float *x, ViennaCLInt offx, ViennaCLInt incx, float *y, ViennaCLInt offy, ViennaCLInt incy)
ViennaCLInt
int ViennaCLInt
Definition: viennacl.hpp:48
viennacl::vector
Definition: forwards.h:266
viennacl::MAIN_MEMORY
Definition: forwards.h:348
viennacl::traits::context
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
Definition: context.hpp:40
vector.hpp
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
viennacl::scalar_vector
Represents a vector consisting of scalars 's' only, i.e. v[i] = s for all i. To be used as an initial...
Definition: vector_def.hpp:87
viennacl::cuda_arg
NumericT * cuda_arg(scalar< NumericT > &obj)
Convenience helper function for extracting the CUDA handle from a ViennaCL scalar. Non-const version.
Definition: common.hpp:39
viennacl::ocl::get_context
viennacl::ocl::context & get_context(long i)
Convenience function for returning the current context.
Definition: backend.hpp:225
viennacl.hpp