#include #include #include #include "cal.h" #include "calcl.h" std::string ILmin= "il_ps_2_0\n" "ret_dyn\n" "end\n"; std::string ILcheck= "il_ps_2_0\n" "dcl_input_generic vObjIndex0.x \n" "dcl_input_position_interp(linear_noperspective) vWinCoord0.xy__\n" "dcl_output_generic o0\n" "itof o0,vObjIndex0.xxxx\n" "mov o0.xy__,vWinCoord0.xy\n" "ret_dyn\n" "end\n"; using namespace std; int main(int argc, char** argv) { int n=256; int n4=n/4; int viewstartx=0; int viewstarty=0; int viewwidth= n; int viewheight=n; if(n%4!=0) { cout << "Sorry, only matrices with size a multiple \ of 4 are supported." << endl; return 1; } std::string kernel0 = ILcheck; calInit(); CALuint numDevices = 0; calDeviceGetCount(&numDevices); cout << "Num devices =" << numDevices << endl; CALdevice device = 0; calDeviceOpen(&device, 0); CALdeviceinfo info; calDeviceGetInfo(&info, 0); CALcontext ctx = 0; calCtxCreate(&ctx, device); CALobject obj0 = NULL; CALimage image0 = NULL; CALlanguage lang0 = CAL_LANGUAGE_IL; if (calclCompile(&obj0, lang0, kernel0.c_str(), info.target) != CAL_RESULT_OK) { cout << "Kernel0 compilation failed. Exiting." << endl; return 1; } else { cout << "Kernel0 compiled fine." << endl; }; if (calclLink(&image0, &obj0, 1) != CAL_RESULT_OK) { cout << "Kernel0 linking failed. Exiting." << endl; return 1; } else { cout << "Kernel0 linked fine." << endl; }; CALresource part0=0; if(calResAllocLocal2D(&part0, device,n4,n, CAL_FORMAT_FLOAT_4, 0) !=CAL_RESULT_OK) { cout << "part0 resource allocation failed." << endl; } else { cout << "part0 fine." << endl; }; float* part0ptr=NULL; CALuint part0pitch=0; calResMap((CALvoid**)&part0ptr, &part0pitch, part0, 0); for (int i = 0; i < n4; ++i) { float* tmp = &part0ptr[i * part0pitch*4]; for(int j = 0; j < n; ++j) { tmp[j] =0.f; } } calResUnmap(part0); CALmem part0mem=0; calCtxGetMem(&part0mem, ctx, part0); CALmodule module0 = 0; calModuleLoad(&module0, ctx, image0); CALfunc func0 = 0; CALname outname0formod0=0; calModuleGetEntry(&func0, ctx, module0, "main"); calModuleGetName(&outname0formod0, ctx, module0, "o0"); calCtxSetMem(ctx, outname0formod0, part0mem); CALevent e = 0; // Change domain here. // Try from e.g. ... // CALdomain domain0 = {0,0, n4, n}; CALdomain domain0 = {1,2, 4, 10}; //CALdomain domain0 = {0,0, 2, 2}; //CALdomain domain0 = {2,2, 2, 2}; //CALdomain domain0 = {1,1, 4, 4}; // Last two parameters appear to be width and height as expected. //Also note the way vObjIndex0 "wraps around" 8x8 blocks of the domain, //based on 2x2 quads (try odd values for x and y...), //presumably related to the rasterization pattern. calCtxRunProgram(&e, ctx, func0, &domain0); while (calCtxIsEventDone(ctx, e) == CAL_RESULT_PENDING);e=0; cout << calGetErrorString()<