本文整理汇总了C++中boost::compute::command_queue类的典型用法代码示例。如果您正苦于以下问题:C++ command_queue类的具体用法?C++ command_queue怎么用?C++ command_queue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了command_queue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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,
InputRange const& initial_delta,
OutputRange& result_prev_delta,
boost::compute::command_queue& queue) {
gpu_vector delta(initial_delta.begin(), initial_delta.end(), queue);
gpu_vector prev_delta(queue.get_context());
for(int i = layers.size()-1; i >= 0; --i) {
auto& l = layers.at(i);
prev_delta.resize(::neu::layer::whole_input_size(l), queue);
auto prev_delta_range = range::to_range(prev_delta);
#ifdef NEU_BENCHMARK_ENABLE
boost::timer t;
#endif //NEU_BENCHMARK_ENABLE
l.backward(
range::to_range(delta), prev_delta_range,
queue);
#ifdef NEU_BENCHMARK_ENABLE
queue.finish();
std::cout << "layer" << i << "\tbackward\t" << t.elapsed() << " secs" << std::endl;
#endif //NEU_BENCHMARK_ENABLE
delta.swap(prev_delta);
}
range::copy(delta, result_prev_delta, queue);
}
示例3: decltype
decltype(auto) matrix_transpose(
InputRange const& input, OutputRange& output,
int row_size, int col_size,
boost::compute::command_queue& queue) {
NEU_ASSERT(row_size*col_size == range::distance(input));
static auto transpose_kernel =
neu::make_kernel(neu::layer::impl::matrix_transpose_kernel_source,
"matrix_transpose", queue.get_context());
transpose_kernel.set_args(
range::get_buffer(input),
static_cast<cl_int>(range::get_begin_index(input)),
range::get_buffer(output),
static_cast<cl_int>(range::get_begin_index(output)),
static_cast<cl_int>(row_size),
static_cast<cl_int>(col_size));
std::size_t global[2] = {
static_cast<std::size_t>(((col_size-1)/32+1)*32),
static_cast<std::size_t>(((row_size-1)/32+1)*32)
};
std::size_t local[2] = {
static_cast<std::size_t>(32),
static_cast<std::size_t>(32)
};
queue.enqueue_nd_range_kernel(transpose_kernel, 2, nullptr, global, local);
}
示例4: 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;
}
示例5: 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));
}
示例6: read
void read(boost::compute::command_queue q, size_t offset,
size_t size, T *host, bool blocking = false
) const
{
if (size) {
if (blocking) {
q.enqueue_read_buffer(
buffer, sizeof(T) * offset, sizeof(T) * size, host
);
} else {
q.enqueue_read_buffer_async(
buffer, sizeof(T) * offset, sizeof(T) * size, host
);
}
}
}
示例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: 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);
}
示例9: device_vector
device_vector(const boost::compute::command_queue &q, size_t n,
const T *host = 0, mem_flags flags = MEM_READ_WRITE)
{
if (host && !(flags & CL_MEM_USE_HOST_PTR))
flags |= CL_MEM_COPY_HOST_PTR;
if (n)
buffer = boost::compute::buffer(q.get_context(), n * sizeof(T),
flags, static_cast<void*>(const_cast<T*>(host)));
}
示例10: generate
void generate(OutputIterator first, OutputIterator last, Function op, boost::compute::command_queue &queue)
{
boost::compute::vector<T> tmp(std::distance(first, last), queue.get_context());
BOOST_COMPUTE_FUNCTION(T, max_random, (const T x),
{
if(get_global_id(0) < 1)
return (ValueType) MAX_RANDOM;
else
return (ValueType) 0;
});
示例11: map
mapped_array map(boost::compute::command_queue q) const {
return mapped_array(
static_cast<T*>(
q.enqueue_map_buffer(
buffer, CL_MAP_READ,
0, size() * sizeof(T)
)
),
buffer_unmapper(q, buffer)
);
}
示例12: 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();
}
示例13: 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();
}
示例14: test_copy_if_odd
void test_copy_if_odd(compute::command_queue &queue)
{
// create input and output vectors on the device
const compute::context &context = queue.get_context();
compute::vector<int> input(PERF_N, context);
compute::vector<int> output(PERF_N, context);
// generate random numbers between 1 and 10
compute::default_random_engine rng(queue);
compute::uniform_int_distribution<int> d(1, 10);
d.generate(input.begin(), input.end(), rng, queue);
BOOST_COMPUTE_FUNCTION(bool, is_odd, (int x),
{
return x & 1;
});
示例15: tesselate_sphere
// tesselates a sphere with radius, phi_slices, and theta_slices. returns
// a shared opencl/opengl buffer containing the vertex data.
compute::opengl_buffer tesselate_sphere(float radius,
size_t phi_slices,
size_t theta_slices,
compute::command_queue &queue)
{
using compute::dim;
const compute::context &context = queue.get_context();
const size_t vertex_count = phi_slices * theta_slices;
// create opengl buffer
GLuint vbo;
vtkgl::GenBuffersARB(1, &vbo);
vtkgl::BindBufferARB(vtkgl::ARRAY_BUFFER, vbo);
vtkgl::BufferDataARB(vtkgl::ARRAY_BUFFER,
sizeof(float) * 4 * vertex_count,
NULL,
vtkgl::STREAM_DRAW);
vtkgl::BindBufferARB(vtkgl::ARRAY_BUFFER, 0);
// create shared opengl/opencl buffer
compute::opengl_buffer vertex_buffer(context, vbo);
// tesselate_sphere kernel source
const char source[] = BOOST_COMPUTE_STRINGIZE_SOURCE(
__kernel void tesselate_sphere(float radius,
uint phi_slices,
uint theta_slices,
__global float4 *vertex_buffer)
{
const uint phi_i = get_global_id(0);
const uint theta_i = get_global_id(1);
const float phi = phi_i * 2.f * M_PI_F / phi_slices;
const float theta = theta_i * 2.f * M_PI_F / theta_slices;
float4 v;
v.x = radius * cos(theta) * cos(phi);
v.y = radius * cos(theta) * sin(phi);
v.z = radius * sin(theta);
v.w = 1.f;
vertex_buffer[phi_i*phi_slices+theta_i] = v;
}
);