Skip to content

Commit

Permalink
[WIP] Update C API for using in Nek5000/NekBone (#73)
Browse files Browse the repository at this point in the history
* Add a function in C API to get device list

* Fix alignment
  • Loading branch information
thilinarmtb authored and dmed256 committed Nov 4, 2017
1 parent ba6a9ef commit 62f82cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/occa/cBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ OCCA_LFUNC void OCCA_RFUNC occaDeviceSetCompilerFlags(occaDevice device,
OCCA_LFUNC const char* OCCA_RFUNC occaDeviceGetCompiler(occaDevice device);
OCCA_LFUNC const char* OCCA_RFUNC occaDeviceGetCompilerEnvScript(occaDevice device);
OCCA_LFUNC const char* OCCA_RFUNC occaDeviceGetCompilerFlags(occaDevice device);
OCCA_LFUNC int OCCA_RFUNC occaDeviceGetID(occaDevice device);
OCCA_LFUNC void OCCA_RFUNC occaDeviceGetDeviceList(int *n, occaDevice** devices);


OCCA_LFUNC uintptr_t OCCA_RFUNC occaDeviceMemorySize(occaDevice device);
Expand Down
16 changes: 16 additions & 0 deletions src/cBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,22 @@ const char* OCCA_RFUNC occaDeviceGetCompilerFlags(occaDevice device) {
return device_.getCompilerEnvScript().c_str();
}

int OCCA_RFUNC occaDeviceGetID(occaDevice device) {
occa::device device_((occa::device_v*) device);
return device_.id();
}

void OCCA_RFUNC occaDeviceGetDeviceList(int *n, occaDevice** devices) {
std::vector<occa::device>& deviceList = occa::getDeviceList();
*n = deviceList.size();

*devices = (occaDevice*) malloc(sizeof(occaDevice)*(*n));

for (int i = 0; i < *n; i++) {
(*devices)[i] = (occaDevice) deviceList[i].getDHandle();
}
}

uintptr_t OCCA_RFUNC occaDeviceMemorySize(occaDevice device) {
occa::device device_((occa::device_v*) device);
return device_.memorySize();
Expand Down

0 comments on commit 62f82cb

Please sign in to comment.