ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
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-2015, 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(" __global "); source.append(numeric_string); source.append(" * result, \n");
51  source.append(" uint4 layout_result) \n");
52  source.append("{ \n");
53  source.append(" for (unsigned int i = get_global_id(0); i < nonzero_rows; i += get_global_size(0)) \n");
54  source.append(" { \n");
55  source.append(" "); source.append(numeric_string); source.append(" dot_prod = 0; \n");
56  source.append(" unsigned int row_end = row_jumper[i+1]; \n");
57  source.append(" for (unsigned int j = row_jumper[i]; j < row_end; ++j) \n");
58  source.append(" dot_prod += elements[j] * x[column_indices[j] * layout_x.y + layout_x.x]; \n");
59  source.append(" result[row_indices[i] * layout_result.y + layout_result.x] = dot_prod; \n");
60  source.append(" } \n");
61  source.append(" } \n");
62 }
63 
65 
67 template<typename NumericT>
69 {
70  static std::string program_name()
71  {
72  return viennacl::ocl::type_to_string<NumericT>::apply() + "_compressed_compressed_matrix";
73  }
74 
75  static void init(viennacl::ocl::context & ctx)
76  {
77  static std::map<cl_context, bool> init_done;
78  if (!init_done[ctx.handle().get()])
79  {
81  std::string numeric_string = viennacl::ocl::type_to_string<NumericT>::apply();
82 
83  std::string source;
84  source.reserve(8192);
85 
86  viennacl::ocl::append_double_precision_pragma<NumericT>(ctx, source);
87 
88  // fully parametrized kernels:
89  generate_vec_mul(source, numeric_string);
90 
91  std::string prog_name = program_name();
92  #ifdef VIENNACL_BUILD_INFO
93  std::cout << "Creating program " << prog_name << std::endl;
94  #endif
95  ctx.add_program(source, prog_name);
96  init_done[ctx.handle().get()] = true;
97  } //if
98  } //init
99 };
100 
101 } // namespace kernels
102 } // namespace opencl
103 } // namespace linalg
104 } // namespace viennacl
105 #endif
106 
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)
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:34
static void apply(viennacl::ocl::context const &)
Definition: utils.hpp:40
const OCL_TYPE & get() const
Definition: handle.hpp:189
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. ...