freepooma-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [pooma-dev] [PATCH] Clean up Tensor.h


From: James Crotinger
Subject: RE: [pooma-dev] [PATCH] Clean up Tensor.h
Date: Mon, 3 Nov 2003 07:32:21 -0700

Hi Richard,

It's been too long for me to comment on the details here. There were places in the code where template meta-programs were used over loops in order to get performance, and some developers (myself included - it's a fun thing to play with but easy to overuse) used these in places where loops would have sufficed (assuming the upper limits were small and were compile-time constants, so that they could be completely unrolled). There was a wave of simplifications (between 2.2 and 2.3 I think) that cleaned most of these out as the meta-programs were adding a lot to compile time. If this is the nature of your changes, and if the changed code still generates good assembly-code, then the Tensor stuff was probably missed during this cleanup.

It does look like your changes make use of template template parameters. This will hurt portability. I don't think those were supported by anyone when this code was written, and I'm not sure how widely they are supported now. Probably the high-performance compilers can handle them, but at least in the past a number of people would do development with Metrowerks and VC++ since they were/are very productive environments, and they've tended to lag on details such as these. I'd probably avoid them for this reason.

        Jim


-----Original Message-----
From: Richard Guenther [mailto:address@hidden]
Sent: Monday, November 03, 2003 5:36 AM
To: address@hidden
Cc: Jeffrey D. Oldham
Subject: [pooma-dev] [PATCH] Clean up Tensor.h

Hi!

I'm staring a lot on Tensor.h and TensorElement.h from time to time.
And I think its very complicated and undocumented. Does anyone remember
what exactly the TensorAssign<> template is doing? And why it was done
this way instead of simple loops? Are the T1 and T2 argument templates
really independend, or are they supposed to have the same tensor structure
(Antisymmentric, Symmetric, etc.) and the same base type?

Anyway, here's some first cleanup to reduce the code one has to look at ;)

Tested on x86 using gcc3.3 and Intel icpc.

Ok?

Richard.


2003Nov03  Richard Guenther <address@hidden>

        * src/Tiny/Tensor.h: remove default implementations of
        (Antisymmentric|Symmetric|Diagonal)TensorAssign<>.
        Use template template parameter specialization
        to get rid of Tensor<> and TensorEngine<> specialization
        duplicates.

===== Tensor.h 1.8 vs edited =====
--- 1.8/r2/src/Tiny/Tensor.h    Mon Nov  3 11:03:34 2003
+++ edited/Tensor.h     Mon Nov  3 13:02:25 2003
@@ -871,64 +871,36 @@
 struct AntisymmetricTensorAssign;

 // 1D partial specialization:
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct AntisymmetricTensorAssign<TensorEngine<1,T,Antisymmetric>,
-  T2,Op,B1,L1,B2,L2>
-{
-  static void apply(TensorEngine<1,T,Antisymmetric> &x, const T2 &y,
-                    Op op=Op())
-  { }
-};
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct AntisymmetricTensorAssign<Tensor<1,T,Antisymmetric>,
-  T2,Op,B1,L1,B2,L2>
+template<template <int, class, class> class T1, class T, class T2, class Op, int B1, int L1, int B2, int L2>
+struct AntisymmetricTensorAssign<T1<1,T,Antisymmetric>,T2,Op,B1,L1,B2,L2>
 {
-  static void apply(Tensor<1,T,Antisymmetric> &x, const T2 &y,
+  static void apply(T1<1,T,Antisymmetric> &x, const T2 &y,
                     Op op=Op())
   { }
 };
+
 // 2D partial specialization:
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct AntisymmetricTensorAssign<TensorEngine<2,T,Antisymmetric>,
+template<template <int, class, class> class T1, class T, class T2, class Op, int B1, int L1, int B2, int L2>
+struct AntisymmetricTensorAssign<T1<2,T,Antisymmetric>,
   T2,Op,B1,L1,B2,L2>
 {
-  static void apply(TensorEngine<2,T,Antisymmetric> &x, const T2 &y,
+  static void apply(T1<2,T,Antisymmetric> &x, const T2 &y,
                     Op op=Op())
   {
-    TensorAssign<TensorEngine<2,T,Antisymmetric>,T2,Op,1,1,0,1>::apply(x,y,op);
-  }
-};
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct AntisymmetricTensorAssign<Tensor<2,T,Antisymmetric>,
-  T2,Op,B1,L1,B2,L2>
-{
-  static void apply(Tensor<2,T,Antisymmetric> &x, const T2 &y,
-                    Op op=Op())
-  {
-    TensorAssign<Tensor<2,T,Antisymmetric>,T2,Op,1,1,0,1>::apply(x,y,op);
+    TensorAssign<T1<2,T,Antisymmetric>,T2,Op,1,1,0,1>::apply(x,y,op);
   }
 };
+
 // 3D partial specialization:
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct AntisymmetricTensorAssign<TensorEngine<3,T,Antisymmetric>,
+template<template <int, class, class> class T1, class T, class T2, class Op, int B1, int L1, int B2, int L2>
+struct AntisymmetricTensorAssign<T1<3,T,Antisymmetric>,
   T2,Op,B1,L1,B2,L2>
 {
-  static void apply(TensorEngine<3,T,Antisymmetric> &x, const T2 &y,
+  static void apply(T1<3,T,Antisymmetric> &x, const T2 &y,
                     Op op=Op())
   {
-    TensorAssign<TensorEngine<3,T,Antisymmetric>,T2,Op,1,1,0,1>::apply(x,y,op);
-    TensorAssign<TensorEngine<3,T,Antisymmetric>,T2,Op,2,1,0,2>::apply(x,y,op);
-  }
-};
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct AntisymmetricTensorAssign<Tensor<3,T,Antisymmetric>,
-  T2,Op,B1,L1,B2,L2>
-{
-  static void apply(Tensor<3,T,Antisymmetric> &x, const T2 &y,
-                    Op op=Op())
-  {
-    TensorAssign<Tensor<3,T,Antisymmetric>,T2,Op,1,1,0,1>::apply(x,y,op);
-    TensorAssign<Tensor<3,T,Antisymmetric>,T2,Op,2,1,0,2>::apply(x,y,op);
+    TensorAssign<T1<3,T,Antisymmetric>,T2,Op,1,1,0,1>::apply(x,y,op);
+    TensorAssign<T1<3,T,Antisymmetric>,T2,Op,2,1,0,2>::apply(x,y,op);
   }
 };

@@ -1148,71 +1120,37 @@
 struct SymmetricTensorAssign;

 // 1D partial specialization:
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct SymmetricTensorAssign<TensorEngine<1,T,Symmetric>,
-  T2,Op,B1,L1,B2,L2>
-{
-  static void apply(TensorEngine<1,T,Symmetric> &x, const T2 &y,
-                    Op op=Op())
-  {
-    TensorAssign<TensorEngine<1,T,Symmetric>,T2,Op,0,1,0,1>::apply(x,y,op);
-  }
-};
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct SymmetricTensorAssign<Tensor<1,T,Symmetric>,
+template<template <int, class, class> class T1, class T, class T2, class Op, int B1, int L1, int B2, int L2>
+struct SymmetricTensorAssign<T1<1,T,Symmetric>,
   T2,Op,B1,L1,B2,L2>
 {
-  static void apply(Tensor<1,T,Symmetric> &x, const T2 &y,
+  static void apply(T1<1,T,Symmetric> &x, const T2 &y,
                     Op op=Op())
   {
-    TensorAssign<Tensor<1,T,Symmetric>,T2,Op,0,1,0,1>::apply(x,y,op);
+    TensorAssign<T1<1,T,Symmetric>,T2,Op,0,1,0,1>::apply(x,y,op);
   }
 };
+
 // 2D partial specialization:
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct SymmetricTensorAssign<TensorEngine<2,T,Symmetric>,
-  T2,Op,B1,L1,B2,L2>
+template<template <int, class, class> class T1, class T, class T2, class Op, int B1, int L1, int B2, int L2>
+struct SymmetricTensorAssign<T1<2,T,Symmetric>,T2,Op,B1,L1,B2,L2>
 {
-  static void apply(TensorEngine<2,T,Symmetric> &x, const T2 &y,
-                    Op op=Op())
+  static void apply(T1<2,T,Symmetric> &x, const T2 &y, Op op=Op())
   {
-    TensorAssign<TensorEngine<2,T,Symmetric>,T2,Op,0,1,0,1>::apply(x,y,op);
-    TensorAssign<TensorEngine<2,T,Symmetric>,T2,Op,1,1,0,2>::apply(x,y,op);
-  }
-};
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct SymmetricTensorAssign<Tensor<2,T,Symmetric>,
-  T2,Op,B1,L1,B2,L2>
-{
-  static void apply(Tensor<2,T,Symmetric> &x, const T2 &y,
-                    Op op=Op())
-  {
-    TensorAssign<Tensor<2,T,Symmetric>,T2,Op,0,1,0,1>::apply(x,y,op);
-    TensorAssign<Tensor<2,T,Symmetric>,T2,Op,1,1,0,2>::apply(x,y,op);
+    TensorAssign<T1<2,T,Symmetric>,T2,Op,0,1,0,1>::apply(x,y,op);
+    TensorAssign<T1<2,T,Symmetric>,T2,Op,1,1,0,2>::apply(x,y,op);
   }
 };
+
 // 3D partial specialization:
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct SymmetricTensorAssign<TensorEngine<3,T,Symmetric>,
-  T2,Op,B1,L1,B2,L2>
+template<template <int, class, class> class T1, class T, class T2, class Op, int B1, int L1, int B2, int L2>
+struct SymmetricTensorAssign<T1<3,T,Symmetric>,T2,Op,B1,L1,B2,L2>
 {
-  static void apply(TensorEngine<3,T,Symmetric> &x, const T2 &y,
-                    Op op=Op())
-  {
-    TensorAssign<TensorEngine<3,T,Symmetric>,T2,Op,0,1,0,1>::apply(x,y,op);
-    TensorAssign<TensorEngine<3,T,Symmetric>,T2,Op,1,1,0,2>::apply(x,y,op);
-    TensorAssign<TensorEngine<3,T,Symmetric>,T2,Op,2,1,0,3>::apply(x,y,op);
-  }
-};
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct SymmetricTensorAssign<Tensor<3,T,Symmetric>,T2,Op,B1,L1,B2,L2>
-{
-  static void apply(Tensor<3,T,Symmetric> &x, const T2 &y,
-                    Op op=Op())
+  static void apply(T1<3,T,Symmetric> &x, const T2 &y, Op op=Op())
   {
-    TensorAssign<Tensor<3,T,Symmetric>,T2,Op,0,1,0,1>::apply(x,y,op);
-    TensorAssign<Tensor<3,T,Symmetric>,T2,Op,1,1,0,2>::apply(x,y,op);
-    TensorAssign<Tensor<3,T,Symmetric>,T2,Op,2,1,0,3>::apply(x,y,op);
+    TensorAssign<T1<3,T,Symmetric>,T2,Op,0,1,0,1>::apply(x,y,op);
+    TensorAssign<T1<3,T,Symmetric>,T2,Op,1,1,0,2>::apply(x,y,op);
+    TensorAssign<T1<3,T,Symmetric>,T2,Op,2,1,0,3>::apply(x,y,op);
   }
 };

@@ -1531,62 +1469,37 @@
 struct DiagonalTensorAssign;

 // 1D partial specialization:
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct DiagonalTensorAssign<TensorEngine<1,T,Diagonal>,T2,Op,B1,L1,B2,L2>
+template<template <int, class, class> class T1, class T, class T2, class Op, int B1, int L1, int B2, int L2>
+struct DiagonalTensorAssign<T1<1,T,Diagonal>,T2,Op,B1,L1,B2,L2>
 {
-  static void apply(TensorEngine<1,T,Diagonal> &x, const T2 &y, Op op=Op())
+  static void apply(T1<1,T,Diagonal> &x, const T2 &y, Op op=Op())
   {
-    TensorAssign<TensorEngine<1,T,Diagonal>,T2,Op,0,1,0,1>::apply(x,y,op);
-  }
-};
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct DiagonalTensorAssign<Tensor<1,T,Diagonal>,T2,Op,B1,L1,B2,L2>
-{
-  static void apply(Tensor<1,T,Diagonal> &x, const T2 &y, Op op=Op())
-  {
-    TensorAssign<Tensor<1,T,Diagonal>,T2,Op,0,1,0,1>::apply(x,y,op);
+    TensorAssign<T1<1,T,Diagonal>,T2,Op,0,1,0,1>::apply(x,y,op);
   }
 };
+
 // 2D partial specialization:
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct DiagonalTensorAssign<TensorEngine<2,T,Diagonal>,T2,Op,B1,L1,B2,L2>
+template<template <int, class, class> class T1, class T, class T2, class Op, int B1, int L1, int B2, int L2>
+struct DiagonalTensorAssign<T1<2,T,Diagonal>,T2,Op,B1,L1,B2,L2>
 {
-  static void apply(TensorEngine<2,T,Diagonal> &x, const T2 &y, Op op=Op())
+  static void apply(T1<2,T,Diagonal> &x, const T2 &y, Op op=Op())
   {
-    TensorAssign<TensorEngine<2,T,Diagonal>,T2,Op,0,1,0,1>::
+    TensorAssign<T1<2,T,Diagonal>,T2,Op,0,1,0,1>::
       apply(x,y,op);
-    TensorAssign<TensorEngine<2,T,Diagonal>,T2,Op,1,1,1,1>::
+    TensorAssign<T1<2,T,Diagonal>,T2,Op,1,1,1,1>::
       apply(x,y,op);
   }
 };
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct DiagonalTensorAssign<Tensor<2,T,Diagonal>,T2,Op,B1,L1,B2,L2>
-{
-  static void apply(Tensor<2,T,Diagonal> &x, const T2 &y, Op op=Op())
-  {
-    TensorAssign<Tensor<2,T,Diagonal>,T2,Op,0,1,0,1>::apply(x,y,op);
-    TensorAssign<Tensor<2,T,Diagonal>,T2,Op,1,1,1,1>::apply(x,y,op);
-  }
-};
+
 // 3D partial specialization:
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct DiagonalTensorAssign<TensorEngine<3,T,Diagonal>,T2,Op,B1,L1,B2,L2>
-{
-  static void apply(TensorEngine<3,T,Diagonal> &x, const T2 &y, Op op=Op())
-  {
-    TensorAssign<TensorEngine<3,T,Diagonal>,T2,Op,0,1,0,1>::apply(x,y,op);
-    TensorAssign<TensorEngine<3,T,Diagonal>,T2,Op,1,1,1,1>::apply(x,y,op);
-    TensorAssign<TensorEngine<3,T,Diagonal>,T2,Op,2,1,2,1>::apply(x,y,op);
-  }
-};
-template<class T, class T2, class Op, int B1, int L1, int B2, int L2>
-struct DiagonalTensorAssign<Tensor<3,T,Diagonal>,T2,Op,B1,L1,B2,L2>
+template<template <int, class, class> class T1, class T, class T2, class Op, int B1, int L1, int B2, int L2>
+struct DiagonalTensorAssign<T1<3,T,Diagonal>,T2,Op,B1,L1,B2,L2>
 {
-  static void apply(Tensor<3,T,Diagonal> &x, const T2 &y, Op op=Op())
+  static void apply(T1<3,T,Diagonal> &x, const T2 &y, Op op=Op())
   {
-    TensorAssign<Tensor<3,T,Diagonal>,T2,Op,0,1,0,1>::apply(x,y,op);
-    TensorAssign<Tensor<3,T,Diagonal>,T2,Op,1,1,1,1>::apply(x,y,op);
-    TensorAssign<Tensor<3,T,Diagonal>,T2,Op,2,1,2,1>::apply(x,y,op);
+    TensorAssign<T1<3,T,Diagonal>,T2,Op,0,1,0,1>::apply(x,y,op);
+    TensorAssign<T1<3,T,Diagonal>,T2,Op,1,1,1,1>::apply(x,y,op);
+    TensorAssign<T1<3,T,Diagonal>,T2,Op,2,1,2,1>::apply(x,y,op);
   }
 };


reply via email to

[Prev in Thread] Current Thread [Next in Thread]