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

📄 gather_direct.br

📁 用于GPU通用计算的编程语言BrookGPU 0.4
💻 BR
字号:
// gather_direct.br// Minimal acceptance test for gather functionality.// It confirms that when we perform a gather with// a constant index, the expected stream element// is fetched.#include <stdio.h>kernel void gather1( float2 index, float a[100], out float b<> ) {	b = a[ index.x ];}kernel void gather2( float2 index, float a[10][10], out float b<> ) {	b = a[ index.xy ];}int main() {	int i, j;	float2 index = float2(3, 4);	float a1< 100 >;	float b1< 100 >;	float a2< 10, 10 >;	float b2< 10, 10 >;	float input_a1[100];	float output_b1[100];	float input_a2[10][10];	float output_b2[10][10];		// initialize data	for( i = 0; i < 10; i++ )	{		for( j = 0; j < 10; j++ )		{			input_a1[10*i+j] = (float)(10*i+j);			input_a2[i][j] = (float)(10*i+j);		}	}	streamRead( a1, input_a1 );	streamRead( a2, input_a1 );		gather1( index, a1, b1 );	gather2( index, a2, b2 );		streamWrite( b1, output_b1 );	streamWrite( b2, output_b2 );		for( i = 0; i < 10; i++ )	{		for( j = 0; j < 10; j++ )			printf( "%3.2f ", output_b1[10*i+j] );		printf("\n");	}		for( i = 0; i < 10; i++ )	{		for( j = 0; j < 10; j++ )			printf( "%3.2f ", output_b2[i][j] );		printf("\n");	}		return 0;}

⌨️ 快捷键说明

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