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

📄 at_stream_fetch.br

📁 用于GPU通用计算的编程语言BrookGPU 0.4
💻 BR
字号:
// at_stream_fetch.br// test address-translation code for// getting elements of an input stream#include <stdio.h>// arbitrary weird stream sizes:#define RESULT_X 5000#define RESULT_Y 24#define A_X 10#define A_Y 6#define B_X 500#define B_Y 48#define C_X 5000#define C_Y 24kernel void clear2( out float2 result<> ) { result = -1; }kernel void getIndexStream2( out float2 result<> ) {	result = (indexof result).xy;}kernel void copy2( float2 input<>, out float2 result<> ) {	result = input;}void checkItem( const char* streamName, const char* dimName, int expected, float actual, int x, int y, int xi, int yi ){	if( (int)actual != expected )	{		printf("FAIL: %s[%d][%d].%s ~ <%d,%d> : expected %d got %f\n", streamName, y, x,dimName,  yi, xi, expected, actual );		exit(0);	}//	else//		printf("%s[%d][%d].%s ~ <%d,%d> : %f\n", streamName, y, x,dimName,  yi, xi, actual );}void check( float* inData, int inOutputX, int inOutputY, int inInputX, int inInputY, const char* streamName ){	float* data = inData;	int x, y;	int xi, yi;		for( y = 0; y < inOutputY; y++ )	for( x = 0; x < inOutputX; x++ )	{		xi = (x * inInputX) / inOutputX;		yi = (y * inInputY) / inOutputY;				checkItem( streamName, "x", xi, *data++, x, y, xi, yi );		checkItem( streamName, "y", yi, *data++, x, y, xi, yi );		//		if( x > 510 ) exit(0);	}}int main( int argc, char** argv ){	float2 result< RESULT_Y, RESULT_X >;	float2 a< A_Y, A_X >;	float2 b< B_Y, B_X >;	float2 c< C_Y, C_X >;		float* data_result = (float*)malloc( RESULT_Y*RESULT_X*sizeof(float2) );		getIndexStream2( a );	getIndexStream2( b );	getIndexStream2( c );		clear2( result );	copy2( a, result );	streamWrite( result, data_result );	check( data_result, RESULT_X, RESULT_Y, A_X, A_Y, "a" );		clear2( result );	copy2( b, result );	streamWrite( result, data_result );	check( data_result, RESULT_X, RESULT_Y, B_X, B_Y, "b" );	clear2( result );	copy2( c, result );	streamWrite( result, data_result );	check( data_result, RESULT_X, RESULT_Y, C_X, C_Y, "c" );	printf( "pass\n" );	return 0;}

⌨️ 快捷键说明

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