Skip to content

Commit

Permalink
Add cuda feed
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Schaetz committed May 17, 2016
1 parent b6d5fa6 commit 7641095
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 16 deletions.
13 changes: 7 additions & 6 deletions .travis.yml
Expand Up @@ -51,17 +51,18 @@ matrix:
- os: linux
env: AURA_BASE=OPENCL
AURA_UNIT_TEST_DEVICE=0
RUNTEST="yes"
compiler: gcc
#- os: osx
#env: AURA_BASE=METAL
# AURA_UNIT_TEST_DEVICE=0
#compiler: clang
- os: osx
env: AURA_BASE=METAL
AURA_UNIT_TEST_DEVICE=0
RUNTEST="no"
compiler: clang



script:
- mkdir -p build && cd build
- cmake -DAURA_BASE="$AURA_BASE" -DAURA_UNIT_TEST_DEVICE="$AURA_UNIT_TEST_DEVICE" ..
- make all
- test/test.basic
- ctest
- if [[ "$RUNTEST" == "yes" ]]; then ctest; fi
4 changes: 3 additions & 1 deletion buildprocess/build.sh
@@ -1,5 +1,7 @@
#!/bin/bash

set -ev

function build_and_test_target()
{
CURDIR=$(pwd)
Expand All @@ -14,7 +16,7 @@ function build_and_test_target()
cd $CURDIR
}

build_and_test_target "METAL"
build_and_test_target "CUDA"
build_and_test_target "METAL"
build_and_test_target "OPENCL"

4 changes: 2 additions & 2 deletions include/boost/aura/base/cuda/device.hpp
Expand Up @@ -53,14 +53,14 @@ class device
}


/// Make context active.
/// @copydoc boost::aura::base::cuda::device::activate()
inline void activate() const
{
AURA_CUDA_SAFE_CALL(cuCtxSetCurrent(context_));
}


/// Make context not active.
/// @copydoc boost::aura::base::cuda::device::deactivate()
inline void deactivate() const
{
AURA_CUDA_SAFE_CALL(cuCtxSetCurrent(NULL));
Expand Down
149 changes: 149 additions & 0 deletions include/boost/aura/base/cuda/feed.hpp
@@ -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

4 changes: 2 additions & 2 deletions include/boost/aura/base/metal/device.hpp
Expand Up @@ -49,14 +49,14 @@ class device
}


/// Make context active.
/// @copydoc boost::aura::base::cuda::device::activate()
inline void activate() const
{
// Pass
}


/// Make context not active.
/// @copydoc boost::aura::base::cuda::device::deactivate()
inline void deactivate() const
{
// Pass
Expand Down
4 changes: 2 additions & 2 deletions include/boost/aura/base/opencl/device.hpp
Expand Up @@ -91,14 +91,14 @@ class device
}


/// Make context active.
/// @copydoc boost::aura::base::cuda::device::activate()
inline void activate() const
{
// Pass
}


/// Make context not active.
/// @copydoc boost::aura::base::cuda::device::deactivate()
inline void deactivate() const
{
// Pass
Expand Down
1 change: 1 addition & 0 deletions include/boost/aura/feed.hpp
Expand Up @@ -20,6 +20,7 @@ namespace aura {
#endif

using base::feed;
using base::wait_for;

} // namespace aura
} // namespace boost
Expand Down
16 changes: 13 additions & 3 deletions test/basic.cpp
Expand Up @@ -3,7 +3,7 @@

#include <boost/aura/device.hpp>
#include <boost/aura/environment.hpp>
//#include <boost/aura/feed.hpp>
#include <boost/aura/feed.hpp>


// _____________________________________________________________________________
Expand Down Expand Up @@ -31,15 +31,25 @@ BOOST_AUTO_TEST_CASE(basic_device_getters)
boost::aura::finalize();
}

/*

// _____________________________________________________________________________
BOOST_AUTO_TEST_CASE(basic_feed)
{
boost::aura::initialize();
{
boost::aura::feed f0();
boost::aura::device d(AURA_UNIT_TEST_DEVICE);
boost::aura::feed f(d);
f.synchronize();
wait_for(f);
auto base_device_handle = f.get_base_device();
auto base_context_handle = f.get_base_context();
auto base_feed_handle = f.get_base_feed();
BOOST_CHECK(f.get_device().get_ordinal() == AURA_UNIT_TEST_DEVICE);
boost::aura::feed f2(std::move(f));
f = std::move(f2);

}
boost::aura::finalize();
}
*/

0 comments on commit 7641095

Please sign in to comment.