Skip to content

Commit

Permalink
[Stream] Split stream as a modeStream_t
Browse files Browse the repository at this point in the history
  • Loading branch information
dmed256 committed Sep 6, 2018
1 parent 8014d59 commit 7735c66
Show file tree
Hide file tree
Showing 60 changed files with 837 additions and 1,022 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ unit-tests: $(tests)
e2e-tests: unit-tests
@$(testPath)/run_examples

$(testPath)/bin/%:$(testPath)/src/%.cpp $(libPath)/libocca.so
$(testPath)/bin/%:$(testPath)/src/%.cpp $(outputs)
@mkdir -p $(abspath $(dir $@))
$(compiler) $(testFlags) $(pthreadFlag) -o $@ $(flags) $< $(paths) $(linkerFlags) -L$(OCCA_DIR)/lib -locca
#=================================================
Expand Down
3 changes: 2 additions & 1 deletion include/occa/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <occa/device.hpp>
#include <occa/kernel.hpp>
#include <occa/memory.hpp>
#include <occa/stream.hpp>

namespace occa {
//---[ Device Functions ]-------------
Expand All @@ -58,7 +59,7 @@ namespace occa {
double timeBetween(const streamTag &startTag,
const streamTag &endTag);

stream createStream();
stream createStream(const occa::properties &props = occa::properties());
stream getStream();
void setStream(stream s);

Expand Down
2 changes: 1 addition & 1 deletion include/occa/c/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ OCCA_LFUNC void OCCA_RFUNC occaLoadKernels(const char *library);

OCCA_LFUNC void OCCA_RFUNC occaFinish();

OCCA_LFUNC occaStream OCCA_RFUNC occaCreateStream();
OCCA_LFUNC occaStream OCCA_RFUNC occaCreateStream(occaProperties props);

OCCA_LFUNC occaStream OCCA_RFUNC occaGetStream();

Expand Down
7 changes: 4 additions & 3 deletions include/occa/c/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ OCCA_LFUNC void OCCA_RFUNC occaDeviceFinish(occaDevice device);
OCCA_LFUNC int OCCA_RFUNC occaDeviceHasSeparateMemorySpace(occaDevice device);

//---[ Stream ]-------------------------
OCCA_LFUNC occaStream OCCA_RFUNC occaDeviceCreateStream(occaDevice device);
OCCA_LFUNC occaStream OCCA_RFUNC occaDeviceCreateStream(occaDevice device,
occaProperties props);

OCCA_LFUNC occaStream OCCA_RFUNC occaDeviceGetStream(occaDevice device);

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

OCCA_LFUNC occaStreamTag OCCA_RFUNC occaDeviceTagStream(occaDevice device);

Expand Down
8 changes: 2 additions & 6 deletions include/occa/c/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,11 @@ typedef struct {
typedef occaType occaDevice;
typedef occaType occaKernel;
typedef occaType occaMemory;
typedef occaType occaStream;

typedef occaType occaJson;
typedef occaType occaProperties;

typedef struct {
occaDevice device;
void *modeStream;
} occaStream;

typedef struct {
double tagTime;
void *modeTag;
Expand Down Expand Up @@ -102,6 +98,7 @@ extern const int OCCA_STRING;
extern const int OCCA_DEVICE;
extern const int OCCA_KERNEL;
extern const int OCCA_MEMORY;
extern const int OCCA_STREAM;

extern const int OCCA_JSON;
extern const int OCCA_PROPERTIES;
Expand Down Expand Up @@ -158,7 +155,6 @@ OCCA_LFUNC occaType OCCA_RFUNC occaString(const char *str);
//======================================

OCCA_LFUNC void OCCA_RFUNC occaFree(occaType value);
OCCA_LFUNC void OCCA_RFUNC occaFreeStream(occaStream stream);

OCCA_END_EXTERN_C

Expand Down
9 changes: 5 additions & 4 deletions include/occa/c/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ namespace occa {
static const int device = 16;
static const int kernel = 17;
static const int memory = 18;
static const int stream = 19;

static const int json = 19;
static const int properties = 20;
static const int json = 20;
static const int properties = 21;
}

occaType defaultOccaType();
Expand Down Expand Up @@ -108,21 +109,22 @@ namespace occa {
occaType newOccaType(occa::device device);
occaType newOccaType(occa::kernel kernel);
occaType newOccaType(occa::memory memory);
occaType newOccaType(occa::stream stream);

occaType newOccaType(const json &json,
const bool needsFree);

occaType newOccaType(const occa::properties &properties,
const bool needsFree);

occaStream newOccaType(occa::stream value);
occaStreamTag newOccaType(occa::streamTag value);

bool isDefault(occaType value);

occa::device device(occaType value);
occa::kernel kernel(occaType value);
occa::memory memory(occaType value);
occa::stream stream(occaType value);

occa::primitive primitive(occaType value);
occa::primitive primitive(occaType value,
Expand All @@ -134,7 +136,6 @@ namespace occa {
occa::properties& properties(occaType value);
const occa::properties& constProperties(occaType value);

occa::stream stream(occaStream value);
occa::streamTag streamTag(occaStreamTag value);
}
}
69 changes: 34 additions & 35 deletions include/occa/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <occa/defines.hpp>
#include <occa/uva.hpp>
#include <occa/kernel.hpp>
#include <occa/stream.hpp>
#include <occa/tools/gc.hpp>

namespace occa {
Expand All @@ -37,8 +38,6 @@ namespace occa {
class modeDevice_t; class device;
class deviceInfo;

typedef void* stream_t;
class stream;
class streamTag;

typedef std::map<std::string, kernel> cachedKernelMap;
Expand All @@ -54,34 +53,54 @@ namespace occa {
gc::ring_t<device> deviceRing;
gc::ring_t<modeKernel_t> kernelRing;
gc::ring_t<modeMemory_t> memoryRing;
gc::ring_t<modeStream_t> streamRing;

ptrRangeMap uvaMap;
memoryVector uvaStaleMemory;

stream_t currentStream;
std::vector<stream_t> streams;
stream currentStream;
std::vector<modeStream_t*> streams;

udim_t bytesAllocated;

cachedKernelMap cachedKernels;

modeDevice_t(const occa::properties &properties_);

template <class modeType_t>
void freeRing(gc::ring_t<modeType_t> ring) {
modeType_t *head = (modeType_t*) ring.head;
if (head) {
modeType_t *ptr = head;
do {
modeType_t *nextPtr = (modeType_t*) ptr->rightRingEntry;
// Remove modeDevice to prevent messing with this ring
ptr->modeDevice = NULL;
delete ptr;
ptr = nextPtr;
} while (ptr != head);
ring.clear();
}
}

void freeResources();

void dontUseRefs();
void addDeviceRef(device *dev);
void removeDeviceRef(device *dev);
bool needsFree() const;

void addKernelRef(modeKernel_t *ker);
void removeKernelRef(modeKernel_t *ker);
void addKernelRef(modeKernel_t *kernel);
void removeKernelRef(modeKernel_t *kernel);

void addMemoryRef(modeMemory_t *memory);
void removeMemoryRef(modeMemory_t *memory);

void addMemoryRef(modeMemory_t *mem);
void removeMemoryRef(modeMemory_t *mem);
void addStreamRef(modeStream_t *stream);
void removeStreamRef(modeStream_t *stream);

//---[ Virtual Methods ]------------
virtual ~modeDevice_t() = 0;
// Must be able to be called multiple times safely
virtual void free() = 0;

virtual void finish() const = 0;

Expand All @@ -92,8 +111,7 @@ namespace occa {
virtual hash_t kernelHash(const occa::properties &props) const = 0;

// |---[ Stream ]------------------
virtual stream_t createStream() const = 0;
virtual void freeStream(stream_t s) const = 0;
virtual modeStream_t* createStream(const occa::properties &props) = 0;

virtual streamTag tagStream() const = 0;
virtual void waitFor(streamTag tag) const = 0;
Expand Down Expand Up @@ -189,6 +207,9 @@ namespace occa {
occa::properties& memoryProperties();
const occa::properties& memoryProperties() const;

occa::properties& streamProperties();
const occa::properties& streamProperties() const;

hash_t hash() const;

udim_t memorySize() const;
Expand All @@ -199,8 +220,7 @@ namespace occa {
bool hasSeparateMemorySpace();

// |---[ Stream ]------------------
stream createStream();
void freeStream(stream s);
stream createStream(const occa::properties &props = occa::properties());

stream getStream();
void setStream(stream s);
Expand Down Expand Up @@ -265,27 +285,6 @@ namespace occa {
//====================================

//---[ stream ]-----------------------
class stream {
public:
modeDevice_t *modeDevice;
stream_t modeStream;

stream();

stream(modeDevice_t *modeDevice_,
stream_t modeStream_);

stream(const stream &other);

stream& operator = (const stream &other);

bool operator == (const occa::stream &other) const;

stream_t getModeStream();

void free();
};

/*
* CUDA : modeTag = CUevent*
* OpenCL : modeTag = cl_event*
Expand Down
3 changes: 0 additions & 3 deletions include/occa/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ namespace occa {
//---[ Virtual Methods ]------------
virtual ~modeKernel_t() = 0;

// Must be able to be called multiple times safely
virtual void free() = 0;

virtual int maxDims() const = 0;
virtual dim maxOuterDims() const = 0;
virtual dim maxInnerDims() const = 0;
Expand Down
3 changes: 0 additions & 3 deletions include/occa/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ namespace occa {
class modeDevice_t; class device;
class kernelArg;


typedef std::map<hash_t,occa::memory> hashedMemoryMap;
typedef hashedMemoryMap::iterator hashedMemoryMapIterator;
typedef hashedMemoryMap::const_iterator cHashedMemoryMapIterator;
Expand Down Expand Up @@ -77,8 +76,6 @@ namespace occa {

//---[ Virtual Methods ]------------
virtual ~modeMemory_t() = 0;
// Must be able to be called multiple times safely
virtual void free() = 0;

virtual kernelArg makeKernelArg() const = 0;

Expand Down
7 changes: 3 additions & 4 deletions include/occa/mode/cuda/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ namespace occa {
device(const occa::properties &properties_);
virtual ~device();

virtual void free();

virtual void finish() const;

virtual bool hasSeparateMemorySpace() const;
Expand All @@ -60,13 +58,14 @@ namespace occa {
virtual hash_t kernelHash(const occa::properties &props) const;

//---[ Stream ]-------------------
virtual stream_t createStream() const;
virtual void freeStream(stream_t s) const;
virtual modeStream_t* createStream(const occa::properties &props);

virtual streamTag tagStream() const;
virtual void waitFor(streamTag tag) const;
virtual double timeBetween(const streamTag &startTag,
const streamTag &endTag) const;

CUstream& getCuStream() const;
//================================

//---[ Kernel ]-------------------
Expand Down
4 changes: 2 additions & 2 deletions include/occa/mode/cuda/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ namespace occa {

~kernel();

CUstream& getCuStream() const;

int maxDims() const;
dim maxOuterDims() const;
dim maxInnerDims() const;

void run() const;
void launcherRun() const;

void free();
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions include/occa/mode/cuda/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ namespace occa {
const occa::properties &properties_ = occa::properties());
~memory();

CUstream& getCuStream() const;

kernelArg makeKernelArg() const;

modeMemory_t* addOffset(const dim_t offset);
Expand All @@ -75,8 +77,6 @@ namespace occa {
const udim_t destOffset = 0,
const udim_t srcOffset = 0,
const occa::properties &props = occa::properties());

void free();
void detach();
};
}
Expand Down
Loading

0 comments on commit 7735c66

Please sign in to comment.