当前位置: 首页>>代码示例>>C++>>正文


C++ Memory::allocateBuffer方法代码示例

本文整理汇总了C++中Memory::allocateBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ Memory::allocateBuffer方法的具体用法?C++ Memory::allocateBuffer怎么用?C++ Memory::allocateBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Memory的用法示例。


在下文中一共展示了Memory::allocateBuffer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: allocateProgramScopeVars

void Program::allocateProgramScopeVars()
{
  deallocateProgramScopeVars();

  Memory *globalMemory = m_context->getGlobalMemory();

  // Create the pointer values for each global variable
  llvm::Module::const_global_iterator itr;
  for (itr = m_module->global_begin(); itr != m_module->global_end(); itr++)
  {
    unsigned addrspace = itr->getType()->getPointerAddressSpace();
    if (addrspace != AddrSpaceGlobal && addrspace != AddrSpaceConstant)
      continue;

    // Allocate global variable
    const llvm::Type *type = itr->getType()->getPointerElementType();
    size_t size = getTypeSize(type);
    size_t ptr = globalMemory->allocateBuffer(size);
    m_totalProgramScopeVarSize += size;

    // Create pointer value
    TypedValue ptrValue =
    {
      sizeof(size_t), 1, new uint8_t[sizeof(size_t)]
    };
    ptrValue.setPointer(ptr);
    m_programScopeVars[&*itr] = ptrValue;
  }

  try
  {
    // Initialize global variables
    for (auto itr  = m_programScopeVars.begin();
              itr != m_programScopeVars.end();
              itr++)
    {
      auto var = llvm::cast<llvm::GlobalVariable>(itr->first);
      const llvm::Constant *initializer = var->getInitializer();
      if (!initializer)
        continue;

      size_t varptr = itr->second.getPointer();
      if (initializer->getType()->getTypeID() == llvm::Type::PointerTyID)
      {
        size_t ptr = resolveConstantPointer(initializer, m_programScopeVars);
        globalMemory->store((uint8_t*)&ptr, varptr, sizeof(size_t));
      }
      else
      {
        size_t size = getTypeSize(initializer->getType());
        uint8_t *data = new uint8_t[size];
        getConstantData((uint8_t*)data, (const llvm::Constant*)initializer);
        globalMemory->store(data, varptr, size);
        delete[] data;
      }
    }
  }
  catch (FatalError& err)
  {
    cerr << endl << "OCLGRIND FATAL ERROR "
         << "(" << err.getFile() << ":" << err.getLine() << ")"
         << endl << err.what()
         << endl << "When initializing program scope global variables"
         << endl;
  }
}
开发者ID:mpflanzer,项目名称:Oclgrind,代码行数:66,代码来源:Program.cpp


注:本文中的Memory::allocateBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。