void init(const char* cfg) { /* get number of Xeon Phi devices */ uint32_t engines = 0; COIEngineGetCount( COI_ISA_MIC, &engines ); if (engines == 0) throw std::runtime_error("No Xeon Phi device found."); /* get engine handle */ COIRESULT result; result = COIEngineGetHandle( COI_ISA_MIC, 0, &engine ); if (result != COI_SUCCESS) throw std::runtime_error("Failed to load engine number " + std::stringOf(0) + ": " + COIResultGetName(result)); /* print info of engine */ COI_ENGINE_INFO info; result = COIEngineGetInfo(engine,sizeof(info),&info); std::cout << "Found Xeon Phi device with " << info.NumCores << " cores and " << (info.PhysicalMemory/1024/1024) << "MB memory" << std::endl; /* create process */ const std::string executable = std::string(tutorialName)+"_xeonphi_device"; result = COIProcessCreateFromFile (engine, executable.c_str(), // The local path to the sink side binary to launch. 0, NULL, // argc and argv for the sink process. false, NULL, // Environment variables to set for the sink process. true, NULL, // Enable the proxy but don't specify a proxy root path. 0, // The amount of memory to reserve for COIBuffers. NULL, // Path to search for dependencies &process // The resulting process handle. ); if (result != COI_SUCCESS) throw std::runtime_error("Failed to create process " + std::string(executable) +": " + COIResultGetName(result)); /* create pipeline */ COI_CPU_MASK cpuMask; result = COIPipelineClearCPUMask(&cpuMask); if (result != COI_SUCCESS) throw std::runtime_error(std::string("COIPipelineClearCPUMask failed: ") + COIResultGetName(result)); result = COIPipelineSetCPUMask(process,info.NumCores-1,0,&cpuMask); result = COIPipelineSetCPUMask(process,info.NumCores-1,1,&cpuMask); result = COIPipelineSetCPUMask(process,info.NumCores-1,2,&cpuMask); result = COIPipelineSetCPUMask(process,info.NumCores-1,3,&cpuMask); if (result != COI_SUCCESS) throw std::runtime_error(std::string("COIPipelineSetCPUMask failed: ") + COIResultGetName(result)); result = COIPipelineCreate(process,cpuMask,0,&pipeline); if (result != COI_SUCCESS) throw std::runtime_error(std::string("COIPipelineCreate failed: ") + COIResultGetName(result)); /* get run functions */ const char *fctNameArray[8] = { "run_init", "run_key_pressed", "run_create_mesh", "run_create_hairset", "run_create_scene", "run_pick", "run_render", "run_cleanup" }; result = COIProcessGetFunctionHandles (process, 8, fctNameArray, &runInit); if (result != COI_SUCCESS) throw std::runtime_error("COIProcessGetFunctionHandles failed: "+std::string(COIResultGetName(result))); /* run init runfunction */ InitData parms; strncpy(parms.cfg,cfg,sizeof(parms.cfg)); result = COIPipelineRunFunction (pipeline, runInit, 0, NULL, NULL, 0, NULL, &parms, sizeof(parms), NULL, 0, NULL); if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result))); }
void device_t<COI>::setup(const int device, const int memoryAllocated){ data = new COIDeviceData_t; OCCA_EXTRACT_DATA(COI, Device); uint32_t deviceCount; OCCA_COI_CHECK("Device: Get Count", COIEngineGetCount(COI_ISA_MIC, &deviceCount)); OCCA_CHECK(device < deviceCount); OCCA_COI_CHECK("Device: Get Handle", COIEngineGetHandle(COI_ISA_MIC, device, &data_.deviceID) ); std::stringstream salt; salt << "COI" << occaCOIMain; std::string cachedBinary = getCachedName("occaCOIMain", salt.str()); struct stat buffer; bool fileExists = (stat(cachedBinary.c_str(), &buffer) == 0); if(fileExists) std::cout << "Found cached binary of [occaCOIMain] in [" << cachedBinary << "]\n"; else{ //---[ Write File ]----------------- std::string prefix, name; getFilePrefixAndName(cachedBinary, prefix, name); const std::string iCachedBinary = prefix + "i_" + name; if(haveFile(cachedBinary)){ std::cout << "Making [" << iCachedBinary << "]\n"; std::ofstream fs; fs.open(iCachedBinary.c_str()); fs << occaCOIMain; fs.close(); std::stringstream command; command << dev->dHandle->compiler << " -o " << cachedBinary << " -x c++" << ' ' << dev->dHandle->compilerFlags << ' ' << iCachedBinary; const std::string &sCommand = command.str(); std::cout << "Compiling [" << functionName << "]\n" << sCommand << "\n\n"; system(sCommand.c_str()); releaseFile(cachedBinary); } else waitForFile(cachedBinary); } // [-] Tentative std::string SINK_LD_LIBRARY_PATH; char *c_SINK_LD_LIBRARY_PATH = getenv("SINK_LD_LIBRARY_PATH"); if(c_SINK_LD_LIBRARY_PATH != NULL) SINK_LD_LIBRARY_PATH = std::string(c_SINK_LD_LIBRARY_PATH); OCCA_COI_CHECK("Device: Initializing", COIProcessCreateFromFile(data_.deviceID, cachedBinary.c_str(), 0 , NULL, true, NULL, true, NULL, memoryAllocated ? memoryAllocated : (4 << 30), // 4 GB SINK_LD_LIBRARY_PATH.c_str(), &(data_.chiefID)) ); const char *kernelNames[] = {"occaKernelWith1Argument" , "occaKernelWith2Arguments" , "occaKernelWith3Arguments" , "occaKernelWith4Arguments" , "occaKernelWith5Arguments" , "occaKernelWith6Arguments" , "occaKernelWith7Arguments" , "occaKernelWith8Arguments" , "occaKernelWith9Arguments" , "occaKernelWith10Arguments", "occaKernelWith11Arguments", "occaKernelWith12Arguments", "occaKernelWith13Arguments", "occaKernelWith14Arguments", "occaKernelWith15Arguments", "occaKernelWith16Arguments", "occaKernelWith17Arguments", "occaKernelWith18Arguments", "occaKernelWith19Arguments", "occaKernelWith20Arguments", "occaKernelWith21Arguments", "occaKernelWith22Arguments", "occaKernelWith23Arguments", "occaKernelWith24Arguments", "occaKernelWith25Arguments"}; // [-] More hard-coding, if you know what I mean OCCA_COI_CHECK("Device: Getting Kernel Wrappers", COIProcessGetFunctionHandles(data_.chiefID, 25, kernelNames, data_.kernelWrapper)); }