CALresource* CalDevice::resAllocRemote2D(int width, int height, CALformat format, CALuint flags) { CALresource newRes; /* Memory will be specific to this device */ if(calResAllocRemote2D(&newRes, &mDevice, 1, width, height, format, flags) != CAL_RESULT_OK) { fprintf(stderr, "ERROR: Could allocate 2D remote resource.\n"); return NULL; } /* TODO: threadsafe */ mResources.push_front(newRes); CALresource* pRes = &*(mResources.begin()); mRefs[pRes] = 1; mOwners[pRes] = this; return pRes; }
static bool init_rc5_72_il4a_nand(u32 Device) { if(CContext[Device].coreID!=CORE_IL4NA) AMDStreamReinitializeDevice(Device); if(!CContext[Device].active) { Log("Thread %u: Device is not supported\n", Device); return false; } else{ switch(CContext[Device].attribs.target) { case CAL_TARGET_600: CContext[Device].domainSizeX=56; CContext[Device].domainSizeY=56; CContext[Device].maxIters=128; break; case CAL_TARGET_610: CContext[Device].domainSizeX=40; CContext[Device].domainSizeY=40; CContext[Device].maxIters=10; break; case CAL_TARGET_630: CContext[Device].domainSizeX=24; CContext[Device].domainSizeY=24; CContext[Device].maxIters=350; break; case CAL_TARGET_670: CContext[Device].domainSizeX=32; CContext[Device].domainSizeY=32; CContext[Device].maxIters=300; break; case CAL_TARGET_7XX: //TODO:domainSize break; case CAL_TARGET_770: CContext[Device].domainSizeX=600; CContext[Device].domainSizeY=600; CContext[Device].maxIters=5; break; case CAL_TARGET_710: //TODO:domainSize CContext[Device].domainSizeX=80; CContext[Device].domainSizeY=80; CContext[Device].maxIters=128; break; case CAL_TARGET_730: CContext[Device].domainSizeX=120; CContext[Device].domainSizeY=120; CContext[Device].maxIters=30; break; case 8: //RV870 CContext[Device].domainSizeX=728; CContext[Device].domainSizeY=728; CContext[Device].maxIters=4; break; case 9: //RV840 CContext[Device].domainSizeX=656; CContext[Device].domainSizeY=656; CContext[Device].maxIters=3; break; case 17://Barts CContext[Device].domainSizeX=904; CContext[Device].domainSizeY=904; CContext[Device].maxIters=3; default: break; } } CALresult result; result=calCtxCreate(&CContext[Device].ctx, CContext[Device].device); if(result!=CAL_RESULT_OK) { Log("Thread %u: creating context failed! Reason:%u\n",Device,result); return false; } CContext[Device].globalRes0=0; if(CContext[Device].attribs.target<20) if(CContext[Device].attribs.memExport) { calResAllocRemote2D(&CContext[Device].globalRes0, &CContext[Device].device, 1, 64, 1, CAL_FORMAT_UINT_1, CAL_RESALLOC_GLOBAL_BUFFER); } //------------------------------------------------------------------------- // Compiling Device Program //------------------------------------------------------------------------- result=compileProgram(&CContext[Device].ctx,&CContext[Device].image,&CContext[Device].module0, (CALchar *)il4ag_nand_src,CContext[Device].attribs.target,CContext[Device].globalRes0); if ( result!= CAL_RESULT_OK) { Log("Core compilation failed. Exiting.\n"); return false; } //------------------------------------------------------------------------- // Allocating and initializing resources //------------------------------------------------------------------------- // Input and output resources CContext[Device].outputRes0=0; if(CContext[Device].attribs.cachedRemoteRAM>0) calResAllocRemote2D(&CContext[Device].outputRes0, &CContext[Device].device, 1, CContext[Device].domainSizeX, CContext[Device].domainSizeY, CAL_FORMAT_UINT_1, CAL_RESALLOC_CACHEABLE); if(!CContext[Device].outputRes0) { if(calResAllocRemote2D(&CContext[Device].outputRes0, &CContext[Device].device, 1, CContext[Device].domainSizeX, CContext[Device].domainSizeY, CAL_FORMAT_UINT_1, 0)!=CAL_RESULT_OK) { Log("Failed to allocate output buffer\n"); return false; } } // Constant resource if(calResAllocRemote1D(&CContext[Device].constRes0, &CContext[Device].device, 1, 3, CAL_FORMAT_UINT_4, 0)!=CAL_RESULT_OK) { Log("Failed to allocate constants buffer\n"); return false; } // Mapping output resource to CPU and initializing values // Getting memory handle from resources result=calCtxGetMem(&CContext[Device].outputMem0, CContext[Device].ctx, CContext[Device].outputRes0); if(result==CAL_RESULT_OK) result=calCtxGetMem(&CContext[Device].constMem0, CContext[Device].ctx, CContext[Device].constRes0); if(result!=CAL_RESULT_OK) { Log("Failed to map resources!\n"); return false; } // Defining entry point for the module result=calModuleGetEntry(&CContext[Device].func0, CContext[Device].ctx, CContext[Device].module0, "main"); if(result==CAL_RESULT_OK) { result=calModuleGetName(&CContext[Device].outName0, CContext[Device].ctx, CContext[Device].module0, "o0"); if(result==CAL_RESULT_OK) result=calModuleGetName(&CContext[Device].constName0, CContext[Device].ctx, CContext[Device].module0, "cb0"); } if(result!=CAL_RESULT_OK) { Log("Failed to get entry points!\n"); return false; } if(CContext[Device].globalRes0) { result=calCtxGetMem(&CContext[Device].globalMem0, CContext[Device].ctx, CContext[Device].globalRes0); if(result==CAL_RESULT_OK) { result=calModuleGetName(&CContext[Device].globalName0, CContext[Device].ctx, CContext[Device].module0, "g[]"); if(result==CAL_RESULT_OK) result=calCtxSetMem(CContext[Device].ctx, CContext[Device].globalName0, CContext[Device].globalMem0); } if(result!=CAL_RESULT_OK) { Log("Failed to allocate global buffer!\n"); return false; } } // Setting input and output buffers // used in the kernel result=calCtxSetMem(CContext[Device].ctx, CContext[Device].outName0, CContext[Device].outputMem0); if(result==CAL_RESULT_OK) result=calCtxSetMem(CContext[Device].ctx, CContext[Device].constName0, CContext[Device].constMem0); if(result!=CAL_RESULT_OK) { Log("Failed to set buffers!\n"); return false; } CContext[Device].coreID=CORE_IL4NA; return true; }