Skip to content

Commit

Permalink
[StreamTag] Split streamTag as a modeStreamTag_t
Browse files Browse the repository at this point in the history
  • Loading branch information
dmed256 committed Sep 6, 2018
1 parent 7735c66 commit f81054d
Show file tree
Hide file tree
Showing 31 changed files with 665 additions and 155 deletions.
1 change: 1 addition & 0 deletions include/occa/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <occa/kernel.hpp>
#include <occa/memory.hpp>
#include <occa/stream.hpp>
#include <occa/streamTag.hpp>

namespace occa {
//---[ Device Functions ]-------------
Expand Down
7 changes: 2 additions & 5 deletions include/occa/c/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,11 @@ typedef occaType occaDevice;
typedef occaType occaKernel;
typedef occaType occaMemory;
typedef occaType occaStream;
typedef occaType occaStreamTag;

typedef occaType occaJson;
typedef occaType occaProperties;

typedef struct {
double tagTime;
void *modeTag;
} occaStreamTag;

//---[ Type Flags ]---------------------
extern const int OCCA_UNDEFINED;
extern const int OCCA_DEFAULT;
Expand All @@ -99,6 +95,7 @@ extern const int OCCA_DEVICE;
extern const int OCCA_KERNEL;
extern const int OCCA_MEMORY;
extern const int OCCA_STREAM;
extern const int OCCA_STREAMTAG;

extern const int OCCA_JSON;
extern const int OCCA_PROPERTIES;
Expand Down
11 changes: 5 additions & 6 deletions include/occa/c/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ namespace occa {
static const int kernel = 17;
static const int memory = 18;
static const int stream = 19;
static const int streamTag = 20;

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

occaType defaultOccaType();
Expand Down Expand Up @@ -110,21 +111,21 @@ namespace occa {
occaType newOccaType(occa::kernel kernel);
occaType newOccaType(occa::memory memory);
occaType newOccaType(occa::stream stream);
occaType newOccaType(occa::streamTag streamTag);

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

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

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::streamTag streamTag(occaType value);

occa::primitive primitive(occaType value);
occa::primitive primitive(occaType value,
Expand All @@ -135,7 +136,5 @@ namespace occa {

occa::properties& properties(occaType value);
const occa::properties& constProperties(occaType value);

occa::streamTag streamTag(occaStreamTag value);
}
}
31 changes: 10 additions & 21 deletions include/occa/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ namespace occa {
class modeKernel_t; class kernel;
class modeMemory_t; class memory;
class modeDevice_t; class device;
class modeStreamTag_t; class streamTag;
class deviceInfo;

class streamTag;

typedef std::map<std::string, kernel> cachedKernelMap;
typedef cachedKernelMap::iterator cachedKernelMapIterator;
typedef cachedKernelMap::const_iterator cCachedKernelMapIterator;
Expand All @@ -54,6 +53,7 @@ namespace occa {
gc::ring_t<modeKernel_t> kernelRing;
gc::ring_t<modeMemory_t> memoryRing;
gc::ring_t<modeStream_t> streamRing;
gc::ring_t<modeStreamTag_t> streamTagRing;

ptrRangeMap uvaMap;
memoryVector uvaStaleMemory;
Expand Down Expand Up @@ -83,6 +83,7 @@ namespace occa {
}
}

// Must be called before ~modeDevice_t()!
void freeResources();

void dontUseRefs();
Expand All @@ -99,6 +100,9 @@ namespace occa {
void addStreamRef(modeStream_t *stream);
void removeStreamRef(modeStream_t *stream);

void addStreamTagRef(modeStreamTag_t *streamTag);
void removeStreamTagRef(modeStreamTag_t *streamTag);

//---[ Virtual Methods ]------------
virtual ~modeDevice_t() = 0;

Expand All @@ -113,10 +117,10 @@ namespace occa {
// |---[ Stream ]------------------
virtual modeStream_t* createStream(const occa::properties &props) = 0;

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

// |---[ Kernel ]------------------
Expand Down Expand Up @@ -283,21 +287,6 @@ namespace occa {
std::ostream& operator << (std::ostream &out,
const occa::device &device);
//====================================

//---[ stream ]-----------------------
/*
* CUDA : modeTag = CUevent*
* OpenCL : modeTag = cl_event*
*/
class streamTag {
public:
double tagTime;
void *modeTag;

streamTag();
streamTag(const double tagTime_,
void *modeTag_);
};
//====================================
}

#endif
6 changes: 3 additions & 3 deletions include/occa/mode/cuda/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ namespace occa {
//---[ Stream ]-------------------
virtual modeStream_t* createStream(const occa::properties &props);

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

CUstream& getCuStream() const;
//================================
Expand Down
48 changes: 48 additions & 0 deletions include/occa/mode/cuda/streamTag.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* 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
*/

#include <occa/defines.hpp>

#if OCCA_CUDA_ENABLED
# ifndef OCCA_MODES_CUDA_STREAMTAG_HEADER
# define OCCA_MODES_CUDA_STREAMTAG_HEADER

#include <cuda.h>

#include <occa/streamTag.hpp>

namespace occa {
namespace cuda {
class streamTag : public occa::modeStreamTag_t {
public:
CUevent cuEvent;

streamTag(modeDevice_t *modeDevice_,
CUevent cuEvent_);

virtual ~streamTag();
};
}
}

# endif
#endif
3 changes: 0 additions & 3 deletions include/occa/mode/cuda/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ namespace occa {
const udim_t bytes,
const occa::properties &props = occa::properties());

CUevent& event(streamTag &tag);
const CUevent& event(const streamTag &tag);

void warn(CUresult errorCode,
const std::string &filename,
const std::string &function,
Expand Down
6 changes: 3 additions & 3 deletions include/occa/mode/opencl/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ namespace occa {
//---[ Stream ]-------------------
virtual modeStream_t* createStream(const occa::properties &props);

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

cl_command_queue& getCommandQueue() const;
//================================
Expand Down
50 changes: 50 additions & 0 deletions include/occa/mode/opencl/streamTag.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* 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
*/

#include <occa/defines.hpp>

#if OCCA_OPENCL_ENABLED
# ifndef OCCA_MODES_OPENCL_STREAMTAG_HEADER
# define OCCA_MODES_OPENCL_STREAMTAG_HEADER

#include <occa/streamTag.hpp>
#include <occa/mode/opencl/headers.hpp>

namespace occa {
namespace opencl {
class streamTag : public occa::modeStreamTag_t {
public:
cl_event clEvent;
double time;

streamTag(modeDevice_t *modeDevice_,
cl_event clEvent_);

virtual ~streamTag();

double getTime();
};
}
}

# endif
#endif
3 changes: 0 additions & 3 deletions include/occa/mode/opencl/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ namespace occa {
const udim_t bytes,
const occa::properties &props = occa::properties());

cl_event& event(streamTag &tag);
const cl_event& event(const streamTag &tag);

void warn(cl_int errorCode,
const std::string &filename,
const std::string &function,
Expand Down
6 changes: 3 additions & 3 deletions include/occa/mode/serial/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ namespace occa {
//---[ Stream ]-------------------
virtual modeStream_t* createStream(const occa::properties &props);

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

//---[ Kernel ]-------------------
Expand Down
44 changes: 44 additions & 0 deletions include/occa/mode/serial/streamTag.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* 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
*/

#include <occa/defines.hpp>

#ifndef OCCA_MODES_SERIAL_STREAMTAG_HEADER
#define OCCA_MODES_SERIAL_STREAMTAG_HEADER

#include <occa/streamTag.hpp>

namespace occa {
namespace serial {
class streamTag : public occa::modeStreamTag_t {
public:
double time;

streamTag(modeDevice_t *modeDevice_,
double time_);

virtual ~streamTag();
};
}
}

#endif
1 change: 0 additions & 1 deletion include/occa/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ namespace occa {
~stream();

private:
void assertInitialized() const;
void setModeStream(modeStream_t *modeStream_);
void removeStreamRef();

Expand Down
Loading

0 comments on commit f81054d

Please sign in to comment.