示例#1
0
  stream device_t<COI>::genStream(){
    OCCA_EXTRACT_DATA(COI, Device);

    coiStream *retStream = new coiStream;

    OCCA_COI_CHECK("Device: Generating a Stream",
                   COIPipelineCreate(data_.chiefID,
                                     NULL, 0,
                                     &(retStream->handle)) );

    return retStream;
  }
示例#2
0
  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)));

  }