ViennaCL - The Vienna Computing Library: viennacl/linalg/opencl/kernels/compressed_compressed_matrix.hpp Source File

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"
23 #include "viennacl/ocl/platform.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>
72 struct compressed_compressed_matrix
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 {
84 viennacl::ocl::DOUBLE_PRECISION_CHECKER<NumericT>::apply(ctx);
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
platform.hpp
Implements a OpenCL platform within ViennaCL.
tools.hpp
Various little tools used here and there in ViennaCL.
viennacl::ocl::context
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
Definition: context.hpp:55
utils.hpp
Provides OpenCL-related utilities.
viennacl::linalg::opencl::kernels::compressed_compressed_matrix::program_name
static std::string program_name()
Definition: compressed_compressed_matrix.hpp:74
viennacl::ocl::context::handle
const viennacl::ocl::handle< cl_context > & handle() const
Returns the context handle.
Definition: context.hpp:611
viennacl::linalg::opencl::kernels::generate_vec_mul
void generate_vec_mul(StringT &source, std::string const &numeric_string)
Definition: compressed_compressed_matrix.hpp:40
viennacl::ocl::DOUBLE_PRECISION_CHECKER::apply
static void apply(viennacl::ocl::context const &)
Definition: utils.hpp:40
viennacl::ocl::handle::get
const OCL_TYPE & get() const
Definition: handle.hpp:191
viennacl::linalg::opencl::kernels::compressed_compressed_matrix::init
static void init(viennacl::ocl::context &ctx)
Definition: compressed_compressed_matrix.hpp:79
kernel.hpp
Representation of an OpenCL kernel in ViennaCL.
viennacl::ocl::type_to_string
Helper class for converting a type to its string representation.
Definition: utils.hpp:57
viennacl::linalg::opencl::kernels::compressed_compressed_matrix
Main kernel class for generating OpenCL kernels for compressed_compressed_matrix. ...
Definition: compressed_compressed_matrix.hpp:72