ViennaCL - The Vienna Computing Library
1.5.2
|
00001 #ifndef VIENNACL_DEVICE_SPECIFIC_TREE_PARSING_TRAVERSE_HPP 00002 #define VIENNACL_DEVICE_SPECIFIC_TREE_PARSING_TRAVERSE_HPP 00003 00004 /* ========================================================================= 00005 Copyright (c) 2010-2013, Institute for Microelectronics, 00006 Institute for Analysis and Scientific Computing, 00007 TU Wien. 00008 Portions of this software are copyright by UChicago Argonne, LLC. 00009 00010 ----------------- 00011 ViennaCL - The Vienna Computing Library 00012 ----------------- 00013 00014 Project Head: Karl Rupp rupp@iue.tuwien.ac.at 00015 00016 (A list of authors and contributors can be found in the PDF manual) 00017 00018 License: MIT (X11), see file LICENSE in the base directory 00019 ============================================================================= */ 00020 00021 00026 #include <set> 00027 00028 #include "CL/cl.h" 00029 00030 #include "viennacl/forwards.h" 00031 00032 #include "viennacl/scheduler/forwards.h" 00033 00034 #include "viennacl/device_specific/utils.hpp" 00035 #include "viennacl/device_specific/forwards.h" 00036 00037 namespace viennacl{ 00038 00039 namespace device_specific{ 00040 00041 namespace tree_parsing{ 00042 00044 class traversal_functor{ 00045 public: 00046 void call_before_expansion(scheduler::statement const &, unsigned int) const { } 00047 void call_after_expansion(scheduler::statement const &, unsigned int) const { } 00048 }; 00049 00051 template<class Fun> 00052 inline void traverse(scheduler::statement const & statement, unsigned int root_idx, Fun const & fun, bool inspect){ 00053 scheduler::statement_node const & root_node = statement.array()[root_idx]; 00054 bool recurse = utils::node_leaf(root_node.op)?inspect:true; 00055 00056 fun.call_before_expansion(statement, root_idx); 00057 00058 //Lhs: 00059 if(recurse) 00060 { 00061 if(root_node.lhs.type_family==scheduler::COMPOSITE_OPERATION_FAMILY) 00062 traverse(statement, root_node.lhs.node_index, fun, inspect); 00063 if(root_node.lhs.type_family != scheduler::INVALID_TYPE_FAMILY) 00064 fun(statement, root_idx, LHS_NODE_TYPE); 00065 } 00066 00067 //Self: 00068 fun(statement, root_idx, PARENT_NODE_TYPE); 00069 00070 //Rhs: 00071 if(recurse && root_node.op.type_family!=scheduler::OPERATION_UNARY_TYPE_FAMILY) 00072 { 00073 if(root_node.rhs.type_family==scheduler::COMPOSITE_OPERATION_FAMILY) 00074 traverse(statement, root_node.rhs.node_index, fun, inspect); 00075 if(root_node.rhs.type_family != scheduler::INVALID_TYPE_FAMILY) 00076 fun(statement, root_idx, RHS_NODE_TYPE); 00077 } 00078 00079 fun.call_after_expansion(statement, root_idx); 00080 00081 00082 } 00083 00084 } 00085 } 00086 } 00087 #endif