Skip to content

Commit

Permalink
[C] Filled missing API methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dmed256 committed Mar 25, 2018
1 parent 1026ff6 commit c68f8f3
Show file tree
Hide file tree
Showing 13 changed files with 546 additions and 251 deletions.
2 changes: 0 additions & 2 deletions examples/1_add_vectors/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ int main(int argc, char **argv) {
//---[ Device setup with string flags ]-------------------
device.setup("mode: 'Serial'");

std::cout << "device.properties = " << device.properties() << '\n';

// device.setup("mode : 'OpenMP', "
// "schedule : 'compact', "
// "chunk : 10");
Expand Down
2 changes: 1 addition & 1 deletion include/occa.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*/
#include "occa/c/defines.h"
#include "occa/c/device.h"
#include "occa/c/kernel.h"
#include "occa/c/memory.h"
#include "occa/c/base.h"
#include "occa/c/properties.h"

// Just in case someone wants to run with an older format than C99
Expand Down
91 changes: 91 additions & 0 deletions include/occa/c/base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* The MIT License (MIT)
*
* Copyright (c) 2014-2018 David Medina and Tim Warburton
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*/

#ifndef OCCA_C_BASE_HEADER
#define OCCA_C_BASE_HEADER

#include "occa/c/defines.h"
#include "occa/c/types.h"

OCCA_START_EXTERN_C
//---[ Globals & Flags ]----------------
OCCA_LFUNC occaProperties OCCA_RFUNC occaSettings();

OCCA_LFUNC void OCCA_RFUNC occaPrintModeInfo();
//======================================

//---[ Device ]-------------------------
OCCA_LFUNC occaDevice OCCA_RFUNC occaHost();

OCCA_LFUNC occaDevice OCCA_RFUNC occaGetDevice();

OCCA_LFUNC void OCCA_RFUNC occaSetDevice(occaDevice device);

OCCA_LFUNC void OCCA_RFUNC occaSetDeviceFromInfo(const char *infos);

OCCA_LFUNC occaProperties OCCA_RFUNC occaDeviceProperties();

OCCA_LFUNC void OCCA_RFUNC occaLoadKernels(const char *library);

OCCA_LFUNC void OCCA_RFUNC occaFinish();

OCCA_LFUNC void OCCA_RFUNC occaWaitFor(occaStreamTag tag);

OCCA_LFUNC occaStream OCCA_RFUNC occaCreateStream();

OCCA_LFUNC occaStream OCCA_RFUNC occaGetStream();

OCCA_LFUNC void OCCA_RFUNC occaSetStream(occaStream stream);

OCCA_LFUNC occaStream OCCA_RFUNC occaWrapStream(void *handle_,
const occaProperties props);

OCCA_LFUNC occaStreamTag OCCA_RFUNC occaTagStream();
//======================================

//---[ Kernel ]-------------------------
OCCA_LFUNC occaKernel OCCA_RFUNC occaBuildKernel(const char *filename,
const char *kernelName,
const occaProperties props);

OCCA_LFUNC occaKernel OCCA_RFUNC occaBuildKernelFromString(const char *str,
const char *kernelName,
const occaProperties props);

OCCA_LFUNC occaKernel OCCA_RFUNC occaBuildKernelFromBinary(const char *filename,
const char *kernelName,
const occaProperties props);
//======================================

//---[ Memory ]-------------------------
OCCA_LFUNC occaMemory OCCA_RFUNC occaMalloc(const occaUDim_t bytes,
const void *src,
occaProperties props);

OCCA_LFUNC void* OCCA_RFUNC occaUMalloc(const occaUDim_t bytes,
const void *src,
occaProperties props);
//======================================

OCCA_END_EXTERN_C

#endif
71 changes: 31 additions & 40 deletions include/occa/c/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,49 @@

OCCA_START_EXTERN_C

//---[ Background ]---------------------
OCCA_LFUNC void OCCA_RFUNC occaSetDevice(occaDevice device);
OCCA_LFUNC occaDevice OCCA_RFUNC occaCreateDevice(occaType info);

OCCA_LFUNC void OCCA_RFUNC occaSetDeviceFromInfo(const char *infos);
OCCA_LFUNC int OCCA_RFUNC occaDeviceIsInitialized(occaDevice device);

OCCA_LFUNC void OCCA_RFUNC occaFinish();
OCCA_LFUNC const char* OCCA_RFUNC occaDeviceMode(occaDevice device);

OCCA_LFUNC void OCCA_RFUNC occaWaitFor(occaStreamTag tag);
OCCA_LFUNC occaProperties OCCA_RFUNC occaDeviceGetProperties(occaDevice device);

OCCA_LFUNC occaStream OCCA_RFUNC occaCreateStream();
OCCA_LFUNC occaProperties OCCA_RFUNC occaDeviceGetKernelProperties(occaDevice device);

OCCA_LFUNC occaStream OCCA_RFUNC occaGetStream();
OCCA_LFUNC occaProperties OCCA_RFUNC occaDeviceGetMemoryProperties(occaDevice device);

OCCA_LFUNC void OCCA_RFUNC occaSetStream(occaStream stream);
OCCA_LFUNC occaUDim_t OCCA_RFUNC occaDeviceMemorySize(occaDevice device);

OCCA_LFUNC occaStream OCCA_RFUNC occaWrapStream(void *handle_,
const occaProperties props);
OCCA_LFUNC occaUDim_t OCCA_RFUNC occaDeviceMemoryAllocated(occaDevice device);

OCCA_LFUNC occaStreamTag OCCA_RFUNC occaTagStream();
//======================================
OCCA_LFUNC void OCCA_RFUNC occaDeviceFinish(occaDevice device);

OCCA_LFUNC void OCCA_RFUNC occaPrintModeInfo();
OCCA_LFUNC int OCCA_RFUNC occaDeviceHasSeparateMemorySpace(occaDevice device);

OCCA_LFUNC occaDevice OCCA_RFUNC occaCreateDevice(occaType info);
//---[ Stream ]-------------------------
OCCA_LFUNC occaStream OCCA_RFUNC occaDeviceCreateStream(occaDevice device);

OCCA_LFUNC const char* OCCA_RFUNC occaDeviceMode(occaDevice device);
OCCA_LFUNC occaStream OCCA_RFUNC occaDeviceGetStream(occaDevice device);

OCCA_LFUNC occaUDim_t OCCA_RFUNC occaDeviceMemorySize(occaDevice device);
OCCA_LFUNC void OCCA_RFUNC occaDeviceSetStream(occaDevice device,
occaStream stream);

OCCA_LFUNC occaUDim_t OCCA_RFUNC occaDeviceMemoryAllocated(occaDevice device);
OCCA_LFUNC occaStream OCCA_RFUNC occaDeviceWrapStream(occaDevice device,
void *handle_,
const occaProperties props);

OCCA_LFUNC occaStreamTag OCCA_RFUNC occaDeviceTagStream(occaDevice device);

OCCA_LFUNC occaUDim_t OCCA_RFUNC occaDeviceBytesAllocated(occaDevice device);
OCCA_LFUNC void OCCA_RFUNC occaDeviceWaitForTag(occaDevice device,
occaStreamTag tag);

OCCA_LFUNC double OCCA_RFUNC occaDeviceTimeBetweenTags(occaDevice device,
occaStreamTag startTag,
occaStreamTag endTag);
//======================================

//---[ Kernel ]-------------------------
OCCA_LFUNC occaKernel OCCA_RFUNC occaDeviceBuildKernel(occaDevice device,
const char *filename,
const char *kernelName,
Expand All @@ -75,7 +85,9 @@ OCCA_LFUNC occaKernel OCCA_RFUNC occaDeviceBuildKernelFromBinary(occaDevice devi
const char *filename,
const char *kernelName,
const occaProperties props);
//======================================

//---[ Memory ]-------------------------
OCCA_LFUNC occaMemory OCCA_RFUNC occaDeviceMalloc(occaDevice device,
const occaUDim_t bytes,
const void *src,
Expand All @@ -85,28 +97,7 @@ OCCA_LFUNC void* OCCA_RFUNC occaDeviceUmalloc(occaDevice device,
const occaUDim_t bytes,
const void *src,
occaProperties props);

OCCA_LFUNC void OCCA_RFUNC occaDeviceFinish(occaDevice device);

OCCA_LFUNC occaStream OCCA_RFUNC occaDeviceCreateStream(occaDevice device);

OCCA_LFUNC occaStream OCCA_RFUNC occaDeviceGetStream(occaDevice device);

OCCA_LFUNC void OCCA_RFUNC occaDeviceSetStream(occaDevice device,
occaStream stream);

OCCA_LFUNC occaStream OCCA_RFUNC occaDeviceWrapStream(occaDevice device,
void *handle_,
const occaProperties props);

OCCA_LFUNC occaStreamTag OCCA_RFUNC occaDeviceTagStream(occaDevice device);

OCCA_LFUNC void OCCA_RFUNC occaDeviceWaitForTag(occaDevice device,
occaStreamTag tag);

OCCA_LFUNC double OCCA_RFUNC occaDeviceTimeBetweenTags(occaDevice device,
occaStreamTag startTag,
occaStreamTag endTag);
//======================================

OCCA_END_EXTERN_C

Expand Down
27 changes: 14 additions & 13 deletions include/occa/c/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,25 @@

OCCA_START_EXTERN_C

//---[ Background ]---------------------
OCCA_LFUNC occaKernel OCCA_RFUNC occaBuildKernel(const char *filename,
const char *kernelName,
const occaProperties props);
OCCA_LFUNC int OCCA_RFUNC occaKernelIsInitialized(occaKernel kernel);

OCCA_LFUNC occaKernel OCCA_RFUNC occaBuildKernelFromString(const char *str,
const char *kernelName,
const occaProperties props);
OCCA_LFUNC const char* OCCA_RFUNC occaKernelMode(occaKernel kernel);

OCCA_LFUNC occaKernel OCCA_RFUNC occaBuildKernelFromBinary(const char *filename,
const char *kernelName,
const occaProperties props);
//======================================
OCCA_LFUNC occaProperties OCCA_RFUNC occaKernelGetProperties(occaKernel kernel);

OCCA_LFUNC occaDevice OCCA_RFUNC occaKernelGetDevice(occaKernel kernel);

OCCA_LFUNC const char* OCCA_RFUNC occaKernelMode(occaKernel kernel);
OCCA_LFUNC const char* OCCA_RFUNC occaKernelName(occaKernel kernel);

OCCA_LFUNC occaDevice OCCA_RFUNC occaKernelGetDevice(occaKernel kernel);
OCCA_LFUNC const char* OCCA_RFUNC occaKernelSourceFilename(occaKernel kernel);

OCCA_LFUNC const char* OCCA_RFUNC occaKernelBinaryFilename(occaKernel kernel);

OCCA_LFUNC int OCCA_RFUNC occaKernelMaxDims(occaKernel kernel);

OCCA_LFUNC occaDim OCCA_RFUNC occaKernelMaxOuterDims(occaKernel kernel);

OCCA_LFUNC occaDim OCCA_RFUNC occaKernelMaxInnerDims(occaKernel kernel);

OCCA_LFUNC void OCCA_RFUNC occaKernelSetRunDims(occaKernel kernel,
occaDim groups,
Expand Down
41 changes: 33 additions & 8 deletions include/occa/c/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,38 @@

OCCA_START_EXTERN_C

//---[ Background ]---------------------
OCCA_LFUNC occaMemory OCCA_RFUNC occaMalloc(const occaUDim_t bytes,
const void *src,
occaProperties props);
OCCA_LFUNC int OCCA_RFUNC occaMemoryIsInitialized(occaMemory memory);

OCCA_LFUNC void* OCCA_RFUNC occaUMalloc(const occaUDim_t bytes,
const void *src,
occaProperties props);
//======================================
OCCA_LFUNC void* OCCA_RFUNC occaMemoryPtr(occaMemory memory);

OCCA_LFUNC occaDevice OCCA_RFUNC occaMemoryGetDevice(occaMemory memory);

OCCA_LFUNC occaProperties OCCA_RFUNC occaMemoryGetProperties(occaMemory memory);

OCCA_LFUNC const char* OCCA_RFUNC occaMemoryMode(occaMemory memory);

OCCA_LFUNC occaUDim_t OCCA_RFUNC occaMemorySize(occaMemory memory);

//---[ UVA ]----------------------------
OCCA_LFUNC int OCCA_RFUNC occaMemoryIsManaged(occaMemory memory);

OCCA_LFUNC int OCCA_RFUNC occaMemoryInDevice(occaMemory memory);

OCCA_LFUNC int OCCA_RFUNC occaMemoryIsStale(occaMemory memory);

OCCA_LFUNC void OCCA_RFUNC occaMemoryStartManaging(occaMemory memory);

OCCA_LFUNC void OCCA_RFUNC occaMemoryStopManaging(occaMemory memory);

OCCA_LFUNC void OCCA_RFUNC occaMemorySyncToDevice(occaMemory memory,
const occaDim_t bytes,
const occaDim_t offset);

OCCA_LFUNC void OCCA_RFUNC occaMemorySyncToHost(occaMemory memory,
const occaDim_t bytes,
const occaDim_t offset);
//======================================

OCCA_LFUNC void OCCA_RFUNC occaMemcpy(void *dest,
const void *src,
const occaUDim_t bytes,
Expand All @@ -63,6 +83,11 @@ OCCA_LFUNC void OCCA_RFUNC occaCopyMemToPtr(void *dest,
const occaUDim_t offset,
occaProperties props);

OCCA_LFUNC void OCCA_RFUNC occaMemoryDetach(occaMemory memory);

OCCA_LFUNC occaMemory OCCA_RFUNC occaWrapCpuMemory(void *ptr,
occaUDim_t bytes);

OCCA_END_EXTERN_C

#endif
8 changes: 4 additions & 4 deletions include/occa/c/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ OCCA_START_EXTERN_C
typedef int64_t occaDim_t;
typedef uint64_t occaUDim_t;

typedef struct {
occaUDim_t x, y, z;
} occaDim;

typedef struct {
int type;
occaUDim_t bytes;
Expand Down Expand Up @@ -93,10 +97,6 @@ extern const int OCCA_MEMORY;
extern const int OCCA_PROPERTIES;
//======================================

typedef struct {
occaUDim_t x, y, z;
} occaDim;

//---[ Globals & Flags ]----------------
extern const occaType occaDefault;
extern const occaUDim_t occaAllBytes;
Expand Down
3 changes: 3 additions & 0 deletions include/occa/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ namespace occa {
operator kernelArg() const;

const std::string& mode() const;
occa::properties& properties();

udim_t size() const;

Expand All @@ -165,6 +166,7 @@ namespace occa {
return (mHandle->size / sizeof(TM));
}

//---[ UVA ]----------------------------
bool isManaged() const;
bool inDevice() const;
bool isStale() const;
Expand All @@ -179,6 +181,7 @@ namespace occa {
bool uvaIsStale() const;
void uvaMarkStale();
void uvaMarkFresh();
//======================================

bool operator == (const occa::memory &m);
bool operator != (const occa::memory &m);
Expand Down
Loading

0 comments on commit c68f8f3

Please sign in to comment.