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

f.ispc (1040B)


      1 export uniform int f()
      2 {
      3     // uniform array shared among gang
      4     uniform int a[] = {0, 1, 2, 3};
      5 
      6     // varying array per programIndex
      7     varying int b[] = {0, 1, 2, 3, 4};
      8 
      9     if (programIndex == 0) {
     10         a[programIndex] = -1;
     11         b[programIndex] = -1;
     12     }
     13     if (programIndex == 1) {
     14         // shared among gang
     15         a[programIndex] = -2;
     16 
     17         // can only access data for this program instance
     18         b[programIndex - 1] = -2;
     19         b[programIndex + 0] = -3;
     20         b[programIndex + 1] = -4;
     21     }
     22 
     23     // you can also define pointers to arrays
     24     uniform int *uniform uupa = a; // OK
     25     uniform int *varying uvpa = a; // OK (address of array is broadcast)
     26     // varying int *uniform vupa = a; // NOT OK!
     27     // varying int *varying vvpa = a; // NOT OK!
     28 
     29     // uniform int *uniform uupb = b; // NOT OK
     30     // uniform int *varying uvpb = b; // NOT OK
     31     varying int *uniform vupb = b; // OK
     32     varying int *varying vvpb = b; // OK
     33 
     34     return reduce_add(a[programIndex]) + reduce_add(b[programIndex]);
     35 }