Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sebastian Schaetz
committed
May 17, 2016
1 parent
b6d5fa6
commit 7641095
Showing
8 changed files
with
179 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
#pragma once | ||
|
||
#include <cuda.h> | ||
#include <boost/aura/base/cuda/device.hpp> | ||
#include <boost/aura/base/cuda/safecall.hpp> | ||
|
||
namespace boost | ||
{ | ||
namespace aura | ||
{ | ||
namespace base_detail | ||
{ | ||
namespace cuda | ||
{ | ||
|
||
|
||
class feed | ||
{ | ||
public: | ||
/// create empty feed object without device and stream | ||
inline explicit feed() | ||
: device_(nullptr) {} | ||
|
||
/** | ||
* create device feed for device | ||
* | ||
* @param d device to create feed for | ||
* | ||
* const device & is not allowed since an actual instance is needed | ||
*/ | ||
inline explicit feed(device& d) | ||
: device_(&d) | ||
{ | ||
device_->activate(); | ||
AURA_CUDA_SAFE_CALL(cuStreamCreate(&feed_, | ||
0 /*CU_STREAM_NON_BLOCKING*/)); | ||
device_->deactivate(); | ||
} | ||
|
||
/** | ||
* move constructor, move feed information here, invalidate other | ||
* | ||
* @param f feed to move here | ||
*/ | ||
feed(feed&& f) | ||
: device_(f.device_) | ||
, feed_(f.feed_) | ||
{ | ||
f.device_ = nullptr; | ||
} | ||
|
||
/** | ||
* move assignment, move feed information here, invalidate other | ||
* | ||
* @param f feed to move here | ||
*/ | ||
feed& operator=(feed&& f) | ||
{ | ||
finalize(); | ||
device_ = f.device_; | ||
feed_ = f.feed_; | ||
f.device_ = nullptr; | ||
return *this; | ||
} | ||
|
||
/// Destroy feed. | ||
inline ~feed() | ||
{ | ||
finalize(); | ||
} | ||
|
||
/// Wait until all commands in the feed have finished. | ||
inline void synchronize() const | ||
{ | ||
device_->activate(); | ||
AURA_CUDA_SAFE_CALL(cuStreamSynchronize(feed_)); | ||
device_->deactivate(); | ||
} | ||
|
||
/// @copydoc boost::aura::base::cuda::device::activate() | ||
inline void activate() const | ||
{ | ||
device_->activate(); | ||
} | ||
|
||
/// @copydoc boost::aura::base::cuda::device::deactivate() | ||
inline void deactivate() const | ||
{ | ||
device_->deactivate(); | ||
} | ||
|
||
/// @copydoc boost::aura::base::cuda::device::get_base_device() | ||
inline const CUdevice & get_base_device() const | ||
{ | ||
return device_->get_base_device(); | ||
} | ||
|
||
/// @copydoc boost::aura::base::cuda::device::get_base_contet() | ||
inline const CUcontext & get_base_context() const | ||
{ | ||
return device_->get_base_context(); | ||
} | ||
|
||
/// Access base feed. | ||
inline const CUstream & get_base_feed() const | ||
{ | ||
return feed_; | ||
} | ||
|
||
// Access device. | ||
const device& get_device() | ||
{ | ||
return *device_; | ||
} | ||
|
||
private: | ||
/// Finalize object. | ||
void finalize() | ||
{ | ||
if(nullptr != device_) | ||
{ | ||
device_->activate(); | ||
AURA_CUDA_SAFE_CALL(cuStreamDestroy(feed_)); | ||
device_->deactivate(); | ||
} | ||
} | ||
|
||
/// Pointer to device the feed was created for | ||
device * device_; | ||
|
||
/// Stream handle | ||
CUstream feed_; | ||
}; | ||
|
||
/** | ||
* @brief wait for a feed to finish all operations | ||
* | ||
* @param f the feed to wait for | ||
*/ | ||
inline void wait_for(feed & f) | ||
{ | ||
f.synchronize(); | ||
} | ||
|
||
} // cuda | ||
} // base_detail | ||
} // aura | ||
} // boost | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters