本文整理汇总了C++中boost::compute::command_queue::finish方法的典型用法代码示例。如果您正苦于以下问题:C++ command_queue::finish方法的具体用法?C++ command_queue::finish怎么用?C++ command_queue::finish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::compute::command_queue
的用法示例。
在下文中一共展示了command_queue::finish方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_fill
inline void test_fill(T v1, T v2, T v3, bc::command_queue queue) {
if(boost::is_same<typename bc::scalar_type<T>::type, bc::double_>::value &&
!queue.get_device().supports_extension("cl_khr_fp64")) {
std::cerr << "Skipping test_fill<" << bc::type_name<T>() << ">() "
"on device which doesn't support cl_khr_fp64" << std::endl;
return;
}
bc::vector<T> vector(4, queue.get_context());
bc::fill(vector.begin(), vector.end(), v1, queue);
queue.finish();
CHECK_RANGE_EQUAL(T, 4, vector, (v1, v1, v1, v1));
vector.resize(1000, queue);
bc::fill(vector.begin(), vector.end(), v2, queue);
queue.finish();
BOOST_CHECK_EQUAL(vector.front(), v2);
BOOST_CHECK_EQUAL(vector.back(), v2);
bc::fill(vector.begin() + 500, vector.end(), v3, queue);
queue.finish();
BOOST_CHECK_EQUAL(vector.front(), v2);
BOOST_CHECK_EQUAL(vector[499], v2);
BOOST_CHECK_EQUAL(vector[500], v3);
BOOST_CHECK_EQUAL(vector.back(), v3);
}
示例2: decltype
static decltype(auto) call(
std::vector<neu::layer::any_layer>& layers,
int batch_size,
InputRange const& initial_input, OutputRange& result_output,
boost::compute::command_queue& queue) {
gpu_vector input(initial_input.begin(), initial_input.end(), queue);
gpu_vector output(queue.get_context());
int i = 0;
for(auto& l : layers) {
output.resize(::neu::layer::output_dim(l)*batch_size, queue);
/*
std::cout << "whole" << ::neu::layer::whole_output_size(l) << std::endl;
std::cout << "i" << i << std::endl;
std::cout << "aa" << output.size() << std::endl;
*/
auto output_range = range::to_range(output);
#ifdef NEU_BENCHMARK_ENABLE
boost::timer t;
#endif //NEU_BENCHMARK_ENABLE
l.test_forward(batch_size,
range::to_range(input), output_range, queue);
#ifdef NEU_BENCHMARK_ENABLE
queue.finish();
std::cout << "layer" << i << "\ttest_forward\t" << t.elapsed() << " secs" << std::endl;
#endif //NEU_BENCHMARK_ENABLE
input.swap(output);
++i;
}
range::copy(input, result_output, queue);
}
示例3: perf_random_number_engine
void perf_random_number_engine(const size_t size,
const size_t trials,
compute::command_queue& queue)
{
typedef typename Engine::result_type T;
// create random number engine
Engine engine(queue);
// create vector on the device
std::cout << "size = " << size << std::endl;
compute::vector<T> vector(size, queue.get_context());
// generate random numbers
perf_timer t;
for(size_t i = 0; i < trials; i++){
t.start();
engine.generate(vector.begin(), vector.end(), queue);
queue.finish();
t.stop();
}
// print result
std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
std::cout << "rate: " << perf_rate<T>(size, t.min_time()) << " MB/s" << std::endl;
}
示例4: test_fill
inline void test_fill(T v1, T v2, T v3, bc::command_queue queue) {
bc::vector<T> vector(4, queue.get_context());
bc::fill(vector.begin(), vector.end(), v1, queue);
queue.finish();
CHECK_RANGE_EQUAL(T, 4, vector, (v1, v1, v1, v1));
vector.resize(1000, queue);
bc::fill(vector.begin(), vector.end(), v2, queue);
queue.finish();
BOOST_CHECK_EQUAL(vector.front(), v2);
BOOST_CHECK_EQUAL(vector.back(), v2);
bc::fill(vector.begin() + 500, vector.end(), v3, queue);
queue.finish();
BOOST_CHECK_EQUAL(vector.front(), v2);
BOOST_CHECK_EQUAL(vector[499], v2);
BOOST_CHECK_EQUAL(vector[500], v3);
BOOST_CHECK_EQUAL(vector.back(), v3);
}
示例5: saxpy
void saxpy(const int num, bool gen = true, int iter = 0)
{
static compute::device gpu;
static compute::context context;
static compute::command_queue queue;
static compute::vector<T> x;
static compute::vector<T> y;
static compute::vector<T> res;
static T alpha = 3.5;
using compute::lambda::_1;
using compute::lambda::_2;
if (gen) {
gpu = compute::system::default_device();
context = compute::context(gpu);
queue = compute::command_queue(context, gpu);
x = compute::vector<T>(num, context);
std::vector<T> h_x(num);
std::generate(h_x.begin(), h_x.end(), rand);
compute::copy(h_x.begin(), h_x.end(), x.begin(), queue);
y = compute::vector<T>(num, context);
std::vector<T> h_y(num);
std::generate(h_y.begin(), h_y.end(), rand);
compute::copy(h_y.begin(), h_y.end(), y.begin(), queue);
res = compute::vector<T>(num, context);
queue.finish();
}
for (int i = 0; i < iter; i++) {
compute::transform(x.begin(), x.end(),
y.begin(), res.begin(),
alpha * _1 + _2,
queue);
}
queue.finish();
}
示例6: test_fill_n
inline void test_fill_n(T v1, T v2, T v3, bc::command_queue queue) {
if(boost::is_same<typename bc::scalar_type<T>::type, bc::double_>::value &&
!queue.get_device().supports_extension("cl_khr_fp64")) {
std::cerr << "Skipping test_fill_n<" << bc::type_name<T>() << ">() "
"on device which doesn't support cl_khr_fp64" << std::endl;
return;
}
bc::vector<T> vector(4, queue.get_context());
bc::fill_n(vector.begin(), 4, v1, queue);
queue.finish();
CHECK_RANGE_EQUAL(T, 4, vector, (v1, v1, v1, v1));
bc::fill_n(vector.begin(), 3, v2, queue);
queue.finish();
CHECK_RANGE_EQUAL(T, 4, vector, (v2, v2, v2, v1));
bc::fill_n(vector.begin() + 1, 2, v3, queue);
queue.finish();
CHECK_RANGE_EQUAL(T, 4, vector, (v2, v3, v3, v1));
bc::fill_n(vector.begin(), 4, v2, queue);
queue.finish();
CHECK_RANGE_EQUAL(T, 4, vector, (v2, v2, v2, v2));
// fill last element
bc::fill_n(vector.end() - 1, 1, v3, queue);
queue.finish();
CHECK_RANGE_EQUAL(T, 4, vector, (v2, v2, v2, v3));
// fill first element
bc::fill_n(vector.begin(), 1, v1, queue);
queue.finish();
CHECK_RANGE_EQUAL(T, 4, vector, (v1, v2, v2, v3));
}
示例7: test_fill_n
inline void test_fill_n(T v1, T v2, T v3, bc::command_queue queue) {
bc::vector<T> vector(4, queue.get_context());
bc::fill_n(vector.begin(), 4, v1, queue);
queue.finish();
CHECK_RANGE_EQUAL(T, 4, vector, (v1, v1, v1, v1));
bc::fill_n(vector.begin(), 3, v2, queue);
queue.finish();
CHECK_RANGE_EQUAL(T, 4, vector, (v2, v2, v2, v1));
bc::fill_n(vector.begin() + 1, 2, v3, queue);
queue.finish();
CHECK_RANGE_EQUAL(T, 4, vector, (v2, v3, v3, v1));
bc::fill_n(vector.begin(), 4, v2, queue);
queue.finish();
CHECK_RANGE_EQUAL(T, 4, vector, (v2, v2, v2, v2));
// fill last element
bc::fill_n(vector.end() - 1, 1, v3, queue);
queue.finish();
CHECK_RANGE_EQUAL(T, 4, vector, (v2, v2, v2, v3));
// fill first element
bc::fill_n(vector.begin(), 1, v1, queue);
queue.finish();
CHECK_RANGE_EQUAL(T, 4, vector, (v1, v2, v2, v3));
}
示例8: perf_accumulate
double perf_accumulate(const compute::vector<T>& data,
const size_t trials,
compute::command_queue& queue)
{
perf_timer t;
for(size_t trial = 0; trial < trials; trial++){
t.start();
compute::accumulate(data.begin(), data.end(), T(0), queue);
queue.finish();
t.stop();
}
return t.min_time();
}