-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial attempt at exposing events to the user
This only works with vector expressions (no additive expressions, no multiexpressions) for now. refs #196
- Loading branch information
Showing
11 changed files
with
454 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#define BOOST_TEST_MODULE Let | ||
#include <boost/test/unit_test.hpp> | ||
#include <vexcl/vector.hpp> | ||
#include <vexcl/let.hpp> | ||
#include <vexcl/reductor.hpp> | ||
#include "context_setup.hpp" | ||
|
||
BOOST_AUTO_TEST_CASE(let_vector_expr) | ||
{ | ||
const size_t n = 16 * 1024; | ||
|
||
std::vector<vex::command_queue> q1(1, ctx.queue(0)); | ||
std::vector<vex::command_queue> q2(1, vex::backend::duplicate_queue(ctx.queue(0))); | ||
|
||
vex::vector<int> x(q1, n); | ||
vex::vector<int> y(q2, n); | ||
|
||
vex::Reductor<size_t> count(q2); | ||
|
||
x = 1; | ||
q1[0].finish(); | ||
|
||
auto e = vex::let(x) = 2; | ||
let(y, e) = x; | ||
|
||
BOOST_CHECK_EQUAL(count(y != 2), 0); | ||
|
||
q1[0].finish(); | ||
|
||
x = 3; e[0] = vex::backend::enqueue_marker(q1[0]); | ||
let(y, e) = x; | ||
|
||
BOOST_CHECK_EQUAL(count(y != 3), 0); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() | ||
|
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,61 @@ | ||
#ifndef VEXCL_BACKEND_COMPUTE_EVENT_HPP | ||
#define VEXCL_BACKEND_COMPUTE_EVENT_HPP | ||
|
||
/* | ||
The MIT License | ||
Copyright (c) 2012-2016 Denis Demidov <[email protected]> | ||
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 SOFTWARE. | ||
*/ | ||
|
||
/** | ||
* \file vexcl/backend/compute/event.hpp | ||
* \author Denis Demidov <[email protected]> | ||
* \brief Bring Boost.Compute events into vex::backend::compute namespace. | ||
*/ | ||
|
||
#include <boost/compute/event.hpp> | ||
#include <boost/compute/wait_list.hpp> | ||
|
||
namespace vex { | ||
namespace backend { | ||
namespace compute { | ||
|
||
using boost::compute::event; | ||
using boost::compute::wait_list; | ||
|
||
inline void wait_list_append(wait_list &dst, const event &e) { | ||
dst.insert(e); | ||
} | ||
|
||
inline void wait_list_append(wait_list &dst, const wait_list &src) { | ||
for(size_t i = 0; i < src.size(); ++i) | ||
dst.insert(src[i]); | ||
} | ||
|
||
inline boost::compute::event enqueue_marker(const boost::compute::command_queue &q) { | ||
return q.enqueue_marker(); | ||
} | ||
|
||
} // namespace compute | ||
} // namespace backend | ||
} // namespace vex | ||
|
||
#endif |
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,97 @@ | ||
#ifndef VEXCL_BACKEND_CUDA_EVENT_HPP | ||
#define VEXCL_BACKEND_CUDA_EVENT_HPP | ||
|
||
/* | ||
The MIT License | ||
Copyright (c) 2012-2016 Denis Demidov <[email protected]> | ||
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 SOFTWARE. | ||
*/ | ||
|
||
/** | ||
* \file vexcl/backend/compute/event.hpp | ||
* \author Denis Demidov <[email protected]> | ||
* \brief Bring Boost.Compute events into vex::backend::compute namespace. | ||
*/ | ||
|
||
#include <vexcl/backend/cuda/context.hpp> | ||
|
||
namespace vex { | ||
namespace backend { | ||
namespace cuda { | ||
|
||
namespace detail { | ||
|
||
template <> | ||
struct deleter_impl<CUevent> { | ||
static void dispose(CUevent e) { | ||
cuda_check( cuEventDestroy(e) ); | ||
} | ||
}; | ||
|
||
} // namespace detail | ||
|
||
class event { | ||
public: | ||
event(const command_queue &q) | ||
: q(q), e( create(q), detail::deleter(q.context().raw()) ) { } | ||
|
||
CUevent raw() const { return e.get(); } | ||
|
||
operator CUevent() const { return e.get(); } | ||
|
||
void wait() const { | ||
cuda_check( cuStreamWaitEvent(q.raw(), e.get(), 0) ); | ||
} | ||
private: | ||
command_queue q; | ||
std::shared_ptr<std::remove_pointer<CUevent>::type> e; | ||
|
||
static CUevent create(const command_queue &q) { | ||
CUevent e; | ||
q.context().set_current(); | ||
|
||
cuda_check( cuEventCreate(&e, CU_EVENT_DEFAULT) ); | ||
cuda_check( cuEventRecord(e, q.raw()) ); | ||
|
||
return e; | ||
} | ||
}; | ||
|
||
typedef std::vector<event> wait_list; | ||
|
||
inline void wait_list_append(wait_list &dst, const event &e) { | ||
dst.push_back(e); | ||
} | ||
|
||
inline void wait_list_append(wait_list &dst, const wait_list &src) { | ||
dst.insert(dst.begin(), src.begin(), src.end()); | ||
} | ||
|
||
inline event enqueue_marker(const command_queue &q) { | ||
return event(q); | ||
} | ||
|
||
} // namespace cuda | ||
} // namespace backend | ||
} // namespace vex | ||
|
||
|
||
#endif |
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
Oops, something went wrong.