ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
scheduler.cpp
Go to the documentation of this file.
1 /* =========================================================================
2  Copyright (c) 2010-2015, Institute for Microelectronics,
3  Institute for Analysis and Scientific Computing,
4  TU Wien.
5  Portions of this software are copyright by UChicago Argonne, LLC.
6 
7  -----------------
8  ViennaCL - The Vienna Computing Library
9  -----------------
10 
11  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
12 
13  (A list of authors and contributors can be found in the PDF manual)
14 
15  License: MIT (X11), see file LICENSE in the base directory
16 ============================================================================= */
17 
30 // include necessary system headers
31 #include <iostream>
32 
33 // include basic scalar and vector types of ViennaCL
34 #include "viennacl/scalar.hpp"
35 #include "viennacl/vector.hpp"
36 #include "viennacl/matrix.hpp"
37 
40 
41 
47 int main()
48 {
49  typedef float ScalarType; // do not change without adjusting the code for the low-level interface below
50 
54  viennacl::vector<ScalarType> vcl_vec1(10);
55  viennacl::vector<ScalarType> vcl_vec2(10);
56  viennacl::vector<ScalarType> vcl_vec3(10);
57 
58  for (unsigned int i = 0; i < 10; ++i)
59  {
60  vcl_vec1[i] = ScalarType(i);
61  vcl_vec2[i] = ScalarType(10 - i);
62  }
63 
82  typedef viennacl::scheduler::statement::container_type NodeContainerType; // this is just std::vector<viennacl::scheduler::statement_node>
83  NodeContainerType expression_nodes(2); //container with two nodes
84 
89  // specify LHS of first node, i.e. vcl_vec3:
90  expression_nodes[0].lhs.type_family = viennacl::scheduler::VECTOR_TYPE_FAMILY; // family of vectors
91  expression_nodes[0].lhs.subtype = viennacl::scheduler::DENSE_VECTOR_TYPE; // a dense vector
92  expression_nodes[0].lhs.numeric_type = viennacl::scheduler::FLOAT_TYPE; // vector consisting of floats
93  expression_nodes[0].lhs.vector_float = &vcl_vec3; // provide pointer to vcl_vec3;
94 
95  // specify assignment operation for this node:
96  expression_nodes[0].op.type_family = viennacl::scheduler::OPERATION_BINARY_TYPE_FAMILY; // this is a binary operation, so both LHS and RHS operands are important
97  expression_nodes[0].op.type = viennacl::scheduler::OPERATION_BINARY_ASSIGN_TYPE; // assignment operation: '='
98 
99  // specify RHS: Just refer to the second node:
100  expression_nodes[0].rhs.type_family = viennacl::scheduler::COMPOSITE_OPERATION_FAMILY; // this links to another node (no need to set .subtype and .numeric_type)
101  expression_nodes[0].rhs.node_index = 1; // index of the other node
102 
107  // LHS
108  expression_nodes[1].lhs.type_family = viennacl::scheduler::VECTOR_TYPE_FAMILY; // family of vectors
109  expression_nodes[1].lhs.subtype = viennacl::scheduler::DENSE_VECTOR_TYPE; // a dense vector
110  expression_nodes[1].lhs.numeric_type = viennacl::scheduler::FLOAT_TYPE; // vector consisting of floats
111  expression_nodes[1].lhs.vector_float = &vcl_vec1; // provide pointer to vcl_vec1
112 
113  // OP
114  expression_nodes[1].op.type_family = viennacl::scheduler::OPERATION_BINARY_TYPE_FAMILY; // this is a binary operation, so both LHS and RHS operands are important
115  expression_nodes[1].op.type = viennacl::scheduler::OPERATION_BINARY_ADD_TYPE; // addition operation: '+'
116 
117  // RHS
118  expression_nodes[1].rhs.type_family = viennacl::scheduler::VECTOR_TYPE_FAMILY; // family of vectors
119  expression_nodes[1].rhs.subtype = viennacl::scheduler::DENSE_VECTOR_TYPE; // a dense vector
120  expression_nodes[1].rhs.numeric_type = viennacl::scheduler::FLOAT_TYPE; // vector consisting of floats
121  expression_nodes[1].rhs.vector_float = &vcl_vec2; // provide pointer to vcl_vec2
122 
123 
127  viennacl::scheduler::statement vec_addition(expression_nodes);
128 
132  std::cout << vec_addition << std::endl;
133 
137  viennacl::scheduler::execute(vec_addition);
138 
142  std::cout << "vcl_vec1: " << vcl_vec1 << std::endl;
143  std::cout << "vcl_vec2: " << vcl_vec2 << std::endl;
144  std::cout << "vcl_vec3: " << vcl_vec3 << std::endl;
145 
149  std::cout << "!!!! TUTORIAL COMPLETED SUCCESSFULLY !!!!" << std::endl;
150 
151  return EXIT_SUCCESS;
152 }
153 
Implementation of the dense matrix class.
Some helper routines for reading/writing/printing scheduler expressions.
void execute(statement const &s)
Definition: execute.hpp:279
std::vector< value_type > container_type
Definition: forwards.h:507
int main()
Definition: scheduler.cpp:119
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
float ScalarType
Definition: fft_1d.cpp:42
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
The main class for representing a statement such as x = inner_prod(y,z); at runtime.
Definition: forwards.h:502
Implementation of the ViennaCL scalar class.