indexof.br

来自「用于GPU通用计算的编程语言BrookGPU 0.4」· BR 代码 · 共 85 行

BR
85
字号
// indexof.br//// Tests the built-in operator 'indexof.' It confirms the invariant that// when a stream is passed as both a stream argument and a gather argument// to a kernel, fetching from the gather argument with the index of the// stream argument should produce the same value as the stream argument.#include <stdio.h>extern void printf();extern void streamRead();extern void streamWrite();kernel voidbar(float d_prime<>, float d[10][10], out float4 e<>, float4 indexofe){  /* this test should make a matrix of 1 and a diagonal of 0's*/  e = float4(d[indexof(d_prime)],             d[indexof(d_prime).xy],             d[indexof(d_prime).xy],             d[1?(indexofe).xy:indexofe.zz]);}kernel voidfoo(float d_prime<>, float d[10][10],out float4 e<>){   bar(d_prime,d,e,indexof(e));}kernel voidtest(float a<>, out float b<>){   b = (indexof(a)).x;}int main(void){  float data_d[10][10];  float d<10, 10>;  float c<10,10>;  float4 e<10, 10>;  float4 data_e[10][10];  float data_c[10][10];  int i,j;  for (i=0; i<10; i++) {    for (j=0; j<10; j++) {      data_d[i][j] = ((float) i*10+j);    }  }  streamRead(d, data_d);  test(d,c);  streamWrite(c, data_c);  printf("Here are the results from the simple indexof test:\n");  for (i=0; i<10; i++) {    for (j=0; j<10; j++) {      printf ("%3.2f  ", (float)(int)data_c[i][j]);    }    printf ("\n");  }  printf ("\n");  foo(d,d,e);  streamWrite(e, data_e);  printf("Here are the results from the advanced indexof test:\n");  for (i=0; i<10; i++) {    for (j=0; j<10; j++) {      if (!(j%2))        printf ("\n");      printf ("%3.2f %3.2f %3.2f %3.2f\t",               data_e[i][j].x, data_e[i][j].y,              data_e[i][j].z, data_e[i][j].w);    }  }  printf("\n");  return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?