示例#1
0
文件: main.cpp 项目: shedsaw/OCCA2
int main(int argc, char **argv){
  createLibrary();
  loadFromLibrary();

  occa::kernelDatabase addVectors =
    occa::library::loadKernelDatabase("addVectors");

  deviceList_t &devices     = occa::getDeviceList();
  deviceList_t::iterator it = devices.begin();

  while(it != devices.end()){
    int entries = 5;

    float *a  = new float[entries];
    float *b  = new float[entries];
    float *ab = new float[entries];

    occa::device &device = *(it++);
    occa::memory o_a, o_b, o_ab;

    for(int i = 0; i < entries; ++i){
      a[i]  = i;
      b[i]  = 1 - i;
      ab[i] = 0;
    }

    o_a  = device.malloc(entries*sizeof(float));
    o_b  = device.malloc(entries*sizeof(float));
    o_ab = device.malloc(entries*sizeof(float));

    int dims = 1;
    int itemsPerGroup(2);
    int groups((entries + itemsPerGroup - 1)/itemsPerGroup);

    device[addVectors].setWorkingDims(dims, itemsPerGroup, groups);

    o_a.copyFrom(a);
    o_b.copyFrom(b);

    addVectors(entries, o_a, o_b, o_ab);

    o_ab.copyTo(ab);

    for(int i = 0; i < 5; ++i)
      std::cout << i << ": " << ab[i] << '\n';

    device[addVectors].free();
    o_a.free();
    o_b.free();
    o_ab.free();

    delete [] a;
    delete [] b;
    delete [] ab;
  }

  return 0;
}
示例#2
0
void Foam::codedBase::updateLibrary
(
    const word& name
) const
{
    const dictionary& dict = this->codeDict();

    dynamicCode::checkSecurity
    (
        "codedBase::updateLibrary()",
        dict
    );

    dynamicCodeContext context(dict);

    // codeName: name + _<sha1>
    // codeDir : name
    dynamicCode dynCode
    (
        name + context.sha1().str(true),
        name
    );
    const fileName libPath = dynCode.libPath();


    // the correct library was already loaded => we are done
    if (libs().findLibrary(libPath))
    {
        return;
    }

    Info<< "Using dynamicCode for " << this->description().c_str()
        << " at line " << dict.startLineNumber()
        << " in " << dict.name() << endl;


    // remove instantiation of fvPatchField provided by library
    this->clearRedirect();

    // may need to unload old library
    unloadLibrary
    (
        oldLibPath_,
        dynamicCode::libraryBaseName(oldLibPath_),
        context.dict()
    );

    // try loading an existing library (avoid compilation when possible)
    if (!loadLibrary(libPath, dynCode.codeName(), context.dict()))
    {
        createLibrary(dynCode, context);

        loadLibrary(libPath, dynCode.codeName(), context.dict());
    }

    // retain for future reference
    oldLibPath_ = libPath;
}
示例#3
0
void Foam::codedFunctionObject::updateLibrary() const
{
    dynamicCode::checkSecurity
    (
        "codedFunctionObject::updateLibrary()",
        dict_
    );

    dynamicCodeContext context(dict_);

    // codeName: redirectType + _<sha1>
    // codeDir : redirectType
    dynamicCode dynCode
    (
        redirectType_ + context.sha1().str(true),
        redirectType_
    );
    const fileName libPath = dynCode.libPath();


    // the correct library was already loaded => we are done
    if (const_cast<Time&>(time_).libs().findLibrary(libPath))
    {
        return;
    }

    Info<< "Using dynamicCode for functionObject " << name()
        << " at line " << dict_.startLineNumber()
        << " in " << dict_.name() << endl;


    // remove instantiation of fvPatchField provided by library
    redirectFunctionObjectPtr_.clear();

    // may need to unload old library
    unloadLibrary
    (
        oldLibPath_,
        dynamicCode::libraryBaseName(oldLibPath_),
        context.dict()
    );

    // try loading an existing library (avoid compilation when possible)
    if (!loadLibrary(libPath, dynCode.codeName(), context.dict()))
    {
        createLibrary(dynCode, context);

        loadLibrary(libPath, dynCode.codeName(), context.dict());
    }

    // retain for future reference
    oldLibPath_ = libPath;
}
void Foam::codedFixedValueFvPatchField<Type>::updateLibrary() const
{
    dynamicCode::checkSecurity
    (
        "codedFixedValueFvPatchField<Type>::updateLibrary()",
        dict_
    );

    // use system/codeDict or in-line
    const dictionary& codeDict =
    (
        dict_.found("code")
      ? dict_
      : this->dict().subDict(redirectType_)
    );

    dynamicCodeContext context(codeDict);

    // codeName: redirectType + _<sha1>
    // codeDir : redirectType
    dynamicCode dynCode
    (
        redirectType_ + context.sha1().str(true),
        redirectType_
    );
    const fileName libPath = dynCode.libPath();


    // the correct library was already loaded => we are done
    if (const_cast<Time&>(this->db().time()).libs().findLibrary(libPath))
    {
        return;
    }

    Info<< "Using dynamicCode for patch " << this->patch().name()
        << " on field " << this->dimensionedInternalField().name() << nl
        << "at line " << codeDict.startLineNumber()
        << " in " << codeDict.name() << endl;


    // remove instantiation of fvPatchField provided by library
    redirectPatchFieldPtr_.clear();

    // may need to unload old library
    unloadLibrary
    (
        oldLibPath_,
        dynamicCode::libraryBaseName(oldLibPath_),
        context.dict()
    );

    // try loading an existing library (avoid compilation when possible)
    if (!loadLibrary(libPath, dynCode.codeName(), context.dict()))
    {
        createLibrary(dynCode, context);

        loadLibrary(libPath, dynCode.codeName(), context.dict());
    }

    // retain for future reference
    oldLibPath_ = libPath;
}