Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ShChannelImpl.hpp

00001 // Sh: A GPU metaprogramming language. 00002 // 00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory 00004 // Project administrator: Michael D. McCool 00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa, 00006 // Michael D. McCool 00007 // 00008 // This software is provided 'as-is', without any express or implied 00009 // warranty. In no event will the authors be held liable for any damages 00010 // arising from the use of this software. 00011 // 00012 // Permission is granted to anyone to use this software for any purpose, 00013 // including commercial applications, and to alter it and redistribute it 00014 // freely, subject to the following restrictions: 00015 // 00016 // 1. The origin of this software must not be misrepresented; you must 00017 // not claim that you wrote the original software. If you use this 00018 // software in a product, an acknowledgment in the product documentation 00019 // would be appreciated but is not required. 00020 // 00021 // 2. Altered source versions must be plainly marked as such, and must 00022 // not be misrepresented as being the original software. 00023 // 00024 // 3. This notice may not be removed or altered from any source 00025 // distribution. 00027 #ifndef SHSTREAMIMPL_HPP 00028 #define SHSTREAMIMPL_HPP 00029 00030 #include "ShStream.hpp" 00031 #include "ShDebug.hpp" 00032 #include "ShVariable.hpp" 00033 #include "ShContext.hpp" 00034 #include "ShProgram.hpp" 00035 #include "ShSyntax.hpp" 00036 #include "ShStatement.hpp" 00037 00038 namespace SH { 00039 00040 template<typename T> 00041 ShChannel<T>::ShChannel() 00042 : ShMetaForwarder(0), 00043 m_node(new ShChannelNode(T::semantic_type, T::typesize)) 00044 { 00045 real_meta(m_node.object()); 00046 } 00047 00048 template<typename T> 00049 ShChannel<T>::ShChannel(const ShMemoryPtr& memory, int count) 00050 : ShMetaForwarder(0), 00051 m_node(new ShChannelNode(T::semantic_type, T::typesize, memory, count)) 00052 { 00053 real_meta(m_node.object()); 00054 } 00055 00056 template<typename T> 00057 void ShChannel<T>::memory(const ShMemoryPtr& memory, int count) 00058 { 00059 m_node->memory(memory, count); 00060 } 00061 00062 template<typename T> 00063 int ShChannel<T>::count() const 00064 { 00065 return m_node->count(); 00066 } 00067 00068 template<typename T> 00069 ShMemoryPtr ShChannel<T>::memory() 00070 { 00071 return m_node->memory(); 00072 } 00073 00074 template<typename T> 00075 ShPointer<const ShMemory> ShChannel<T>::memory() const 00076 { 00077 return m_node->memory(); 00078 } 00079 00080 template<typename T> 00081 ShChannelNodePtr ShChannel<T>::node() 00082 { 00083 return m_node; 00084 } 00085 00086 template<typename T> 00087 const ShChannelNodePtr ShChannel<T>::node() const 00088 { 00089 return m_node; 00090 } 00091 00092 template<typename T> 00093 T ShChannel<T>::operator()() 00094 { 00095 // TODO: shError() maybe instead. 00096 SH_DEBUG_ASSERT(ShContext::current()->parsing()); 00097 00098 T t; 00099 ShVariable streamVar(m_node); 00100 ShStatement stmt(t, SH_OP_FETCH, streamVar); 00101 00102 ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt); 00103 00104 return t; 00105 } 00106 template<typename T> 00107 const T ShChannel<T>::operator()() const 00108 { 00109 // TODO: shError() maybe instead. 00110 SH_DEBUG_ASSERT(ShContext::current()->parsing()); 00111 00112 T t; 00113 ShVariable streamVar(m_node); 00114 ShStatement stmt(t, SH_OP_FETCH, streamVar); 00115 00116 ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt); 00117 00118 return t; 00119 } 00120 00121 template<typename T> 00122 ShProgram connect(const ShChannel<T>& stream, 00123 const ShProgram& program) 00124 { 00125 ShProgram nibble = SH_BEGIN_PROGRAM() { 00126 typename T::OutputType out = stream(); 00127 } SH_END_PROGRAM; 00128 return connect(nibble, program); 00129 } 00130 00131 template<typename T> 00132 ShProgram operator<<(const ShProgram& program, 00133 const ShChannel<T>& stream) 00134 { 00135 return connect(stream, program); 00136 } 00137 00138 template<typename T> 00139 ShChannel<T>& ShChannel<T>::operator=(const ShProgram& program) 00140 { 00141 ShStream stream(*this); 00142 stream = program; 00143 return *this; 00144 } 00145 00146 // Put these here for dependency reasons, even though they are member 00147 // functions of ShProgram 00148 template<typename T0> 00149 ShProgram ShProgram::operator()(const ShChannel<T0>& t0) const 00150 { 00151 return (*this) << t0; 00152 } 00153 00154 template<typename T0, typename T1> 00155 ShProgram ShProgram::operator()(const ShChannel<T0>& t0, 00156 const ShChannel<T1>& t1) const 00157 { 00158 return (*this) << t0 << t1; 00159 } 00160 00161 template<typename T0, typename T1, typename T2> 00162 ShProgram ShProgram::operator()(const ShChannel<T0>& t0, 00163 const ShChannel<T1>& t1, 00164 const ShChannel<T2>& t2) const 00165 { 00166 return (*this) << t0 << t1 << t2; 00167 } 00168 00169 template<typename T0, typename T1, typename T2, typename T3> 00170 ShProgram ShProgram::operator()(const ShChannel<T0>& t0, 00171 const ShChannel<T1>& t1, 00172 const ShChannel<T2>& t2, 00173 const ShChannel<T3>& t3) const 00174 { 00175 return (*this) << t0 << t1 << t2 << t3; 00176 } 00177 00178 template<typename T0, typename T1, typename T2, typename T3, 00179 typename T4> 00180 ShProgram ShProgram::operator()(const ShChannel<T0>& t0, 00181 const ShChannel<T1>& t1, 00182 const ShChannel<T2>& t2, 00183 const ShChannel<T3>& t3, 00184 const ShChannel<T4>& t4) const 00185 { 00186 return (*this) << t0 << t1 << t2 << t3 << t4; 00187 } 00188 00189 } 00190 00191 00192 #endif

Generated on Mon Oct 18 14:17:38 2004 for Sh by doxygen 1.3.7