ViennaCL - The Vienna Computing Library  1.7.1
Free open-source GPU-accelerated linear algebra and solver library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
compressed_compressed_matrix.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_OPENCL_KERNELS_COMPRESSED_COMPRESSED_MATRIX_HPP
2 #define VIENNACL_LINALG_OPENCL_KERNELS_COMPRESSED_COMPRESSED_MATRIX_HPP
3 
4 /* =========================================================================
5  Copyright (c) 2010-2016, 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 manual)
17 
18  License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20 
21 #include "viennacl/tools/tools.hpp"
22 #include "viennacl/ocl/kernel.hpp"
24 #include "viennacl/ocl/utils.hpp"
25 
28 namespace viennacl
29 {
30 namespace linalg
31 {
32 namespace opencl
33 {
34 namespace kernels
35 {
36 
38 
39 template<typename StringT>
40 void generate_vec_mul(StringT & source, std::string const & numeric_string)
41 {
42  source.append("__kernel void vec_mul( \n");
43  source.append(" __global const unsigned int * row_jumper, \n");
44  source.append(" __global const unsigned int * row_indices, \n");
45  source.append(" __global const unsigned int * column_indices, \n");
46  source.append(" __global const "); source.append(numeric_string); source.append(" * elements, \n");
47  source.append(" uint nonzero_rows, \n");
48  source.append(" __global const "); source.append(numeric_string); source.append(" * x, \n");
49  source.append(" uint4 layout_x, \n");
50  source.append(" "); source.append(numeric_string); source.append(" alpha, \n");
51  source.append(" __global "); source.append(numeric_string); source.append(" * result, \n");
52  source.append(" uint4 layout_result, \n");
53  source.append(" "); source.append(numeric_string); source.append(" beta) \n");
54  source.append("{ \n");
55  source.append(" for (unsigned int i = get_global_id(0); i < nonzero_rows; i += get_global_size(0)) \n");
56  source.append(" { \n");
57  source.append(" "); source.append(numeric_string); source.append(" dot_prod = 0; \n");
58  source.append(" unsigned int row_end = row_jumper[i+1]; \n");
59  source.append(" for (unsigned int j = row_jumper[i]; j < row_end; ++j) \n");
60  source.append(" dot_prod += elements[j] * x[column_indices[j] * layout_x.y + layout_x.x]; \n");
61 
62  source.append(" if (beta != 0) result[row_indices[i] * layout_result.y + layout_result.x] += alpha * dot_prod; \n");
63  source.append(" else result[row_indices[i] * layout_result.y + layout_result.x] = alpha * dot_prod; \n");
64  source.append(" } \n");
65  source.append(" } \n");
66 }
67 
69 
71 template<typename NumericT>
73 {
74  static std::string program_name()
75  {
76  return viennacl::ocl::type_to_string<NumericT>::apply() + "_compressed_compressed_matrix";
77  }
78 
79  static void init(viennacl::ocl::context & ctx)
80  {
81  static std::map<cl_context, bool> init_done;
82  if (!init_done[ctx.handle().get()])
83  {
85  std::string numeric_string = viennacl::ocl::type_to_string<NumericT>::apply();
86 
87  std::string source;
88  source.reserve(8192);
89 
90  viennacl::ocl::append_double_precision_pragma<NumericT>(ctx, source);
91 
92  // fully parametrized kernels:
93  generate_vec_mul(source, numeric_string);
94 
95  std::string prog_name = program_name();
96  #ifdef VIENNACL_BUILD_INFO
97  std::cout << "Creating program " << prog_name << std::endl;
98  #endif
99  ctx.add_program(source, prog_name);
100  init_done[ctx.handle().get()] = true;
101  } //if
102  } //init
103 };
104 
105 } // namespace kernels
106 } // namespace opencl
107 } // namespace linalg
108 } // namespace viennacl
109 #endif
110 
Implements a OpenCL platform within ViennaCL.
Various little tools used here and there in ViennaCL.
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
Definition: context.hpp:55
Provides OpenCL-related utilities.
const viennacl::ocl::handle< cl_context > & handle() const
Returns the context handle.
Definition: context.hpp:611
void generate_vec_mul(StringT &source, std::string const &numeric_string)
static void apply(viennacl::ocl::context const &)
Definition: utils.hpp:40
const OCL_TYPE & get() const
Definition: handle.hpp:191
Representation of an OpenCL kernel in ViennaCL.
Helper class for converting a type to its string representation.
Definition: utils.hpp:57
Main kernel class for generating OpenCL kernels for compressed_compressed_matrix. ...