ViennaCL - The Vienna Computing Library  1.6.0
Free open-source GPU-accelerated linear algebra and solver library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
common.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_OPENCL_COMMON_HPP_
2 #define VIENNACL_LINALG_OPENCL_COMMON_HPP_
3 
4 /* =========================================================================
5  Copyright (c) 2010-2014, Institute for Microelectronics,
6  Institute for Analysis and Scientific Computing,
7  TU Wien.
8  Portions of this software are copyright by UChicago Argonne, LLC.
9 
10  -----------------
11  ViennaCL - The Vienna Computing Library
12  -----------------
13 
14  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15 
16  (A list of authors and contributors can be found in the PDF manual)
17 
18  License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20 
25 #include <cmath>
26 
27 #include "viennacl/forwards.h"
29 
31 
32 namespace viennacl
33 {
34 namespace linalg
35 {
36 namespace opencl
37 {
38 namespace detail
39 {
40 
41 
42 template<typename NumericT>
43 ocl::kernel & legacy_kernel_for_matrix(matrix_base<NumericT> const & M, std::string const & kernel_name)
44 {
45  viennacl::ocl::context & ctx = traits::opencl_context(M);
46  viennacl::ocl::program * program;
47  if (M.row_major())
48  {
50  KernelClass::init(ctx);
51  program = &ctx.get_program(KernelClass::program_name());
52  }
53  else
54  {
56  KernelClass::init(ctx);
57  program = &ctx.get_program(KernelClass::program_name());
58  }
59  return program->get_kernel(kernel_name);
60 }
61 
62 
63 inline cl_uint make_options(vcl_size_t length, bool reciprocal, bool flip_sign)
64 {
65  return static_cast<cl_uint>( ((length > 1) ? (cl_uint(length) << 2) : 0) + (reciprocal ? 2 : 0) + (flip_sign ? 1 : 0) );
66 }
67 
68 
70 inline std::string sparse_dense_matmult_kernel_name(bool B_transposed, bool B_row_major, bool C_row_major)
71 {
72  if (B_transposed)
73  {
74  if (B_row_major && C_row_major)
75  return "trans_mat_mult_row_row";
76  if (B_row_major && !C_row_major)
77  return "trans_mat_mult_row_col";
78  if (!B_row_major && C_row_major)
79  return "trans_mat_mult_col_row";
80 
81  return "trans_mat_mult_col_col";
82  }
83 
84  if (B_row_major && C_row_major)
85  return "mat_mult_row_row";
86  if (B_row_major && !C_row_major)
87  return "mat_mult_row_col";
88  if (!B_row_major && C_row_major)
89  return "mat_mult_col_row";
90 
91  return "mat_mult_col_col";
92 }
93 
94 
95 
96 template<typename SomeT>
97 ocl::device const & current_device(SomeT const & obj) { return traits::opencl_handle(obj).context().current_device(); }
98 
99 inline std::string op_to_string(op_abs) { return "abs"; }
100 inline std::string op_to_string(op_acos) { return "acos"; }
101 inline std::string op_to_string(op_asin) { return "asin"; }
102 inline std::string op_to_string(op_atan) { return "atan"; }
103 inline std::string op_to_string(op_ceil) { return "ceil"; }
104 inline std::string op_to_string(op_cos) { return "cos"; }
105 inline std::string op_to_string(op_cosh) { return "cosh"; }
106 inline std::string op_to_string(op_exp) { return "exp"; }
107 inline std::string op_to_string(op_fabs) { return "fabs"; }
108 inline std::string op_to_string(op_floor) { return "floor"; }
109 inline std::string op_to_string(op_log) { return "log"; }
110 inline std::string op_to_string(op_log10) { return "log10"; }
111 inline std::string op_to_string(op_sin) { return "sin"; }
112 inline std::string op_to_string(op_sinh) { return "sinh"; }
113 inline std::string op_to_string(op_sqrt) { return "sqrt"; }
114 inline std::string op_to_string(op_tan) { return "tan"; }
115 inline std::string op_to_string(op_tanh) { return "tanh"; }
116 
117 } //namespace detail
118 } //namespace opencl
119 } //namespace linalg
120 } //namespace viennacl
121 
122 
123 #endif
A tag class representing the cosh() function.
Definition: forwards.h:154
A tag class representing the tan() function.
Definition: forwards.h:180
Implements a OpenCL platform within ViennaCL.
Represents an OpenCL kernel within ViennaCL.
Definition: kernel.hpp:58
viennacl::ocl::program & get_program(std::string const &name)
Returns the program with the provided name.
Definition: context.hpp:534
std::string sparse_dense_matmult_kernel_name(bool B_transposed, bool B_row_major, bool C_row_major)
Returns the OpenCL kernel string for the operation C = A * B with A sparse, B, C dense matrices...
Definition: common.hpp:70
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
Definition: context.hpp:54
A tag class representing the modulus function for integers.
Definition: forwards.h:136
A tag class representing the ceil() function.
Definition: forwards.h:150
A class representing a compute device (e.g. a GPU)
Definition: device.hpp:49
This file provides the forward declarations for the main types used within ViennaCL.
ocl::kernel & legacy_kernel_for_matrix(matrix_base< NumericT > const &M, std::string const &kernel_name)
Definition: common.hpp:43
A tag class representing the log() function.
Definition: forwards.h:170
A tag class representing the tanh() function.
Definition: forwards.h:182
A tag class representing the fabs() function.
Definition: forwards.h:158
A tag class representing the atan() function.
Definition: forwards.h:146
A tag class representing the sinh() function.
Definition: forwards.h:176
A tag class representing the exp() function.
Definition: forwards.h:156
cl_uint make_options(vcl_size_t length, bool reciprocal, bool flip_sign)
Definition: common.hpp:63
Main kernel class for generating OpenCL kernels for operations on/with dense matrix objects of type v...
Definition: matrix.hpp:768
ocl::device const & current_device(SomeT const &obj)
Definition: common.hpp:97
A tag class representing the sqrt() function.
Definition: forwards.h:178
std::size_t vcl_size_t
Definition: forwards.h:74
Wrapper class for an OpenCL program.
Definition: program.hpp:42
A tag class representing the sin() function.
Definition: forwards.h:174
bool row_major() const
Definition: matrix_def.hpp:239
A tag class representing the floor() function.
Definition: forwards.h:162
A tag class representing the asin() function.
Definition: forwards.h:140
void init()
Definition: Random.hpp:25
A tag class representing the acos() function.
Definition: forwards.h:138
viennacl::ocl::kernel & get_kernel(std::string const &name)
Returns the kernel with the provided name.
Definition: context.hpp:775
std::string op_to_string(op_abs)
Definition: common.hpp:99
A tag class representing the log10() function.
Definition: forwards.h:172
A tag class representing the cos() function.
Definition: forwards.h:152
Runtime generation of OpenCL kernels for matrix operations.