⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 constant.br

📁 用于GPU通用计算的编程语言BrookGPU 0.4
💻 BR
字号:
/* constant.br -- * *      This program tests handling of constant arguments to kernels. * */#include <stdio.h>/* * k1 -- * *      Copies the first constant argument into the output stream. */kernel voidk1(float n, float a, float2 b, float3 c, float4 d, out float4 s<>){   s = float4(a, 0, 0, 0);}/* * k2 -- * *      Copies the second constant argument into the output stream. */kernel voidk2(float n, float a, float2 b, float3 c, float4 d, out float4 s<>){   s = float4(b.x, b.y, 0, 0);}/* * k3 -- * *      Copies the third constant argument into the output stream. */kernel voidk3(float n, float a, float2 b, float3 c, float4 d, out float4 s<>){   s = float4(c.x, c.y, c.z, 0);}/* * k4 -- * *      Copies the fourth constant argument into the output stream. */kernel voidk4(float n, float a, float2 b, float3 c, float4 d, out float4 s<>){   s = float4(d.x, d.y, d.z, d.w);}/* * k -- * *      Copies the n-th constant argument into the output stream. */kernel voidk(float n, float a, float2 b, float3 c, float4 d, out float4 s<>){   if (n == 1.0) {      s = float4(a, n, 0, 0);   } else if (n == 2.0) {      s = float4(b.x, b.y, 0, 0);   } else if (n == 3.0) {      s = float4(c.x, c.y, c.z, 0);   } else if (n == 4.0) {      s = d;   } else {      s = float4(0, 0, 0, 0);   }}intmain(int argc, char *argv[]){   float4 data[10];   float4 s<10>;   float4 d = float4(5.1f, 1.5f, 4.2f, 2.4f);   float3 c = float3(0.1f, 0.2f, 0.3f);   float2 b = float2(67.89f, 98.76f);   float a = 12.34f;   int i;   for (i = 1; i <= 4; i++) {      int j;      switch(i) {      case 1:         k1(i * 1.0f, a, b, c, d, s);         break;      case 2:         k2(i * 1.0f, a, b, c, d, s);         break;      case 3:         k3(i * 1.0f, a, b, c, d, s);         break;      case 4:         k4(i * 1.0f, a, b, c, d, s);         break;      default:         break;      }      streamWrite(s, data);      printf("Results with n = %d and a static kernel:\n", i);      printf("00: ");      for (j = 0; j < (int) (sizeof data / sizeof data[0]); j++) {         printf("(%4.2f, %4.2f, %4.2f, %4.2f) ",                data[j].x, data[j].y, data[j].z, data[j].w);         if ((j % 2) == 1) printf("\n%02d: ", j+1);      }      printf("\n\n");      k(i * 1.0f, a, b, c, d, s);      streamWrite(s, data);      printf("Results with n = %d and a conditional kernel:\n", i);      printf("00: ");      for (j = 0; j < (int) (sizeof data / sizeof data[0]); j++) {         printf("(%4.2f, %4.2f, %4.2f, %4.2f) ",                data[j].x, data[j].y, data[j].z, data[j].w);         if ((j % 2) == 1) printf("\n%02d: ", j+1);      }      printf("\n\n");   }   return 0;}

⌨️ 快捷键说明

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