/* Init CAL, check device capabilities, and prepare new kernel from workunit parameters */ CALresult separationCALInit(MWCALInfo* ci, const CLRequest* clr) { CALresult err; err = calInit(); if (err != CAL_RESULT_OK) { cal_warn("Failed to init CAL", err); return err; } err = calExtSupported(0x8009); if (err != CAL_RESULT_OK) { cal_warn("calCtxWaitForEvents not supported\n", err); return err; } err = calExtGetProc((CALextproc*) &mw_calCtxWaitForEvents, 0x8009, "calCtxWaitForEvents"); if (err != CAL_RESULT_OK) { cal_warn("Error getting calCtxWaitForEvents", err); return err; } err = mwGetCALInfo(ci, clr->devNum); if (err != CAL_RESULT_OK) { cal_warn("Failed to get CAL info", err); calShutdown(); return err; } printCALInfo(ci); if (!checkDeviceCapabilities(&ci->devAttribs)) { warn("Device failed capability check\n"); mwCALShutdown(ci); return CAL_RESULT_ERROR; } return CAL_RESULT_OK; }
A5IlPair::A5IlPair(A5Il* cont, int dev, int dp, int rounds,A5JobQueue* q) : mNumRounds(rounds), mController(cont), mState(0), mDp(dp), mWaitState(false), mTicks(0), mAttention(0), mFreeRound(0), mSingleMode(false), mJobQueue(q) { mDevNo = dev; mMaxCycles = 327650; // CAL setup assert((dev>=0)&&(dev<CalDevice::getNumDevices())); mDev = CalDevice::createDevice(dev); assert(mDev); mNum = mDev->getDeviceAttribs()->wavefrontSize * mDev->getDeviceAttribs()->numberOfSIMD; printf("Num threads %i\n", mNum ); mResState = mDev->resAllocLocal1D(4*mNum, CAL_FORMAT_UINT_4, CAL_RESALLOC_CACHEABLE| CAL_RESALLOC_GLOBAL_BUFFER); mResRoundFunc = mDev->resAllocLocal1D(MAX_RFTABLE_ENTRIES, CAL_FORMAT_UINT_2, 0); mResAttention = mDev->resAllocLocal1D(mNum, CAL_FORMAT_UINT_2, CAL_RESALLOC_CACHEABLE); mResAttentionSingle = mDev->resAllocLocal1D(mNum, CAL_FORMAT_UINT_1, CAL_RESALLOC_CACHEABLE); /* Lazy check to ensure that memory has been allocated */ assert(mResState); assert(mResRoundFunc); assert(mResAttention); assert(mResAttentionSingle); /** * Load Compile and Link kernels */ unsigned char* kernel = getKernel(0); assert(kernel); if (calclCompile(&mObjectDouble, CAL_LANGUAGE_IL, (const CALchar*)kernel, mDev->getDeviceInfo()->target) != CAL_RESULT_OK) { assert(!"Compilation failed."); } freeKernel(kernel); if (calclLink (&mImageDouble, &mObjectDouble, 1) != CAL_RESULT_OK) { assert(!"Link failed."); } #if DISASSEMBLE gDisFile = fopen("disassembly_double.txt","w"); calclDisassembleImage(mImageDouble, logger); fclose(gDisFile); #endif mCtx = mDev->getContext(); mModuleDouble = new CalModule(mCtx); if (mModuleDouble==0) { assert(!"Could not create module"); } if (!mModuleDouble->Load(mImageDouble)) { assert(!"Could not load module image"); } /* repeat for single kernel */ kernel = getKernel(1); assert(kernel); if (calclCompile(&mObjectSingle, CAL_LANGUAGE_IL, (const CALchar*)kernel, mDev->getDeviceInfo()->target) != CAL_RESULT_OK) { assert(!"Compilation failed."); } freeKernel(kernel); if (calclLink (&mImageSingle, &mObjectSingle, 1) != CAL_RESULT_OK) { assert(!"Link failed."); } #if DISASSEMBLE gDisFile = fopen("disassembly_single.txt","w"); calclDisassembleImage(mImageSingle, logger); fclose(gDisFile); #endif mCtx = mDev->getContext(); mModuleSingle = new CalModule(mCtx); if (mModuleSingle==0) { assert(!"Could not create module"); } if (!mModuleSingle->Load(mImageSingle)) { assert(!"Could not load module image"); } unsigned int *dataPtr = NULL; CALuint pitch = 0; if (mSingleMode) { mModule = mModuleSingle; mModule->Bind("o0",mResAttentionSingle); } else { mModule = mModuleDouble; mModule->Bind("o0",mResAttention); } mModule->Bind("g[]",mResState); mModule->Bind("i0",mResRoundFunc); /* Init debug counters */ if (!Ext_calCtxCreateCounter) { calExtGetProc( (CALvoid**)&Ext_calCtxCreateCounter, CAL_EXT_COUNTERS, "calCtxCreateCounter"); } Ext_calCtxCreateCounter( &mCounter, *mCtx, CAL_COUNTER_IDLE ); if (!Ext_calCtxBeginCounter) { calExtGetProc( (CALvoid**)&Ext_calCtxBeginCounter, CAL_EXT_COUNTERS, "calCtxBeginCounter"); } Ext_calCtxBeginCounter( *mCtx, mCounter ); if (!Ext_calCtxEndCounter) { calExtGetProc( (CALvoid**)&Ext_calCtxEndCounter, CAL_EXT_COUNTERS, "calCtxEndCounter"); } if (!Ext_calCtxDestroyCounter) { calExtGetProc( (CALvoid**)&Ext_calCtxDestroyCounter, CAL_EXT_COUNTERS, "calCtxDestroyCounter"); } if (!Ext_calCtxGetCounter) { calExtGetProc( (CALvoid**)&Ext_calCtxGetCounter, CAL_EXT_COUNTERS, "calCtxGetCounter"); } /* Init free list */ int jobs = mNum * 2; mJobLimit = jobs; mJobs = new A5Il::JobPiece_s[jobs]; for(int i=0; i<jobs; i++) { mJobs[i].next_free = i-1; mJobs[i].idle = true; } mFree = jobs - 1; mNumJobs = 0; populate(); };