cs205-lecture-examples

Example codes used during Harvard CS205 lectures
git clone https://git.0xfab.ch/cs205-lecture-examples.git
Log | Files | Refs | README | LICENSE

kernels.ispc (877B)


      1 export void aos()
      2 {
      3     struct Foo {
      4         float x, y, z;
      5     };
      6     uniform Foo a[4] = {
      7         {0, 1, 2},
      8         {3, 4, 5},
      9         {6, 7, 8},
     10         {9, 10, 11},
     11     };
     12     int index = programIndex; // varying int
     13     float v = a[index].x;
     14 }
     15 
     16 export void hybrid_soa()
     17 {
     18     struct Foo4 {
     19         float x[4], y[4], z[4];
     20     };
     21     uniform Foo4 a[2] = {
     22         {{0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11}},
     23         {{12, 13, 14, 15}, {16, 17, 18, 19}, {20, 21, 22, 23}},
     24     };
     25     int index = programIndex; // varying int
     26     float v = a[index / 4].x[index & 3];
     27 }
     28 
     29 export void short_soa()
     30 {
     31     struct Foo {
     32         float x, y, z;
     33     };
     34     soa<4> struct Foo a[2] = {
     35         {{0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11}},
     36         {{12, 13, 14, 15}, {16, 17, 18, 19}, {20, 21, 22, 23}},
     37     };
     38     int index = programIndex; // varying int
     39     float v = a[index].x;
     40 }