cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

roddomi
Journeyman III

IL shader for vector copying

I am trying to write an IL shader to copy a vector from one buffer to another. I am getting incorrect results. Here's my code:

This is what I get:

B[0] = 1
B[1] = 0
B[2] = 0
B[3] = 1
B[4] = 0
B[5] = 0
B[6] = 0
B[7] = 1
B[8] = 0
B[9] = 0

 

Thank you.

#include <stdio.h> #include <string.h> #include "cal.h" #include "calcl.h" int hA[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; int hB[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; const CALchar* ILKernel = "il_cs_2_0\n" "dcl_num_thread_per_group 10\n" "dcl_resource_id(0)_type(unknown,unnorm)_fmtx(unknown)_fmty(unknown)_fmtz(unknown)_fmtw(unknown)\n" "load_resource(0) r1, vAbsTidFlat.x\n" "mov g[vAbsTidFlat.x], r1\n" "end\n"; int main(void) { CALresult result; // initialize CAL result = calInit(); // open device CALdevice device = 0; result = calDeviceOpen(&device, 0); // query device info CALdeviceinfo info; result = calDeviceGetInfo(&info, 0); // create context CALcontext context; result = calCtxCreate(&context, device); // compile CALobject object = NULL; result = calclCompile(&object, CAL_LANGUAGE_IL, ILKernel, info.target); // link CALimage image = NULL; result = calclLink(&image, &object, 1); // allocate resources CALresource dARes, dBRes; result = calResAllocLocal1D(&dARes, device, 10, CAL_FORMAT_SIGNED_INT32_1, 0); result = calResAllocLocal1D(&dBRes, device, 10, CAL_FORMAT_SIGNED_INT32_1, 0); // map resources to CPU CALvoid *data; CALuint pitch = 0; CALmem dAMem, dBMem; result = calResMap(&data, &pitch, dARes, 0); memcpy(data, hA, 10 * sizeof(int)); result = calResUnmap(dARes); result = calResMap(&data, &pitch, dBRes, 0); memcpy(data, hB, 10 * sizeof(int)); result = calResUnmap(dBRes); // get memory handles result = calCtxGetMem(&dAMem, context, dARes); result = calCtxGetMem(&dBMem, context, dBRes); // load module CALmodule module = 0; result = calModuleLoad(&module, context, image); // query symbols in module CALfunc func = 0; CALname dAName = 0, dBName = 0; result = calModuleGetEntry(&func, context, module, "main"); result = calModuleGetName(&dAName, context, module, "i0"); result = calModuleGetName(&dBName, context, module, "g[]"); // bind symbols to memory handles result = calCtxSetMem(context, dAName, dAMem); result = calCtxSetMem(context, dBName, dBMem); // invoke the kernel CALevent event = 0; CALprogramGrid pg; pg.func = func; pg.flags = 0; pg.gridBlock.width = 10; pg.gridBlock.height = 1; pg.gridBlock.depth = 1; pg.gridSize.width = 1; pg.gridSize.height = 1; pg.gridSize.depth = 1; result = calCtxRunProgramGrid(&event, context, &pg); if (result != CAL_RESULT_OK) { printf("%s\n", calGetErrorString()); } while (calCtxIsEventDone(context, event) == CAL_RESULT_PENDING); // read resource back result = calResMap(&data, &pitch, dBRes, 0); memcpy(hB, data, 10 * sizeof(int)); result = calResUnmap(dBRes); // clean up // unload module calModuleUnload(context, module); // free object and image calclFreeImage(image); calclFreeObject(object); // release memory handle calCtxReleaseMem(context, dAMem); calCtxReleaseMem(context, dBMem); // deallocate resources calResFree(dARes); calResFree(dBRes); // destroy context calCtxDestroy(context); // close device calDeviceClose(device); // shutdown CAL calShutdown(); int i; for (i = 0 ; i < 10 ; i++) { printf("B[%d] = %d\n", i, hB); } return 0; }

0 Likes
0 Replies