本文整理汇总了C++中vex::Context::queue方法的典型用法代码示例。如果您正苦于以下问题:C++ Context::queue方法的具体用法?C++ Context::queue怎么用?C++ Context::queue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vex::Context
的用法示例。
在下文中一共展示了Context::queue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: make_pair
std::pair<double,double> benchmark_spmv_ccsr(
const vex::Context &ctx, vex::profiler<> &prof
)
{
// Construct matrix for 3D Poisson problem in cubic domain.
const uint n = 128;
const uint N = n * n * n;
const uint M = 1024;
double time_elapsed;
const real h2i = (n - 1) * (n - 1);
std::vector<size_t> idx;
std::vector<size_t> row(3);
std::vector<int> col(8);
std::vector<real> val(8);
std::vector<real> X(n * n * n, static_cast<real>(1e-2));
std::vector<real> Y(n * n * n, 0);
idx.reserve(n * n * n);
row[0] = 0;
row[1] = 1;
row[2] = 8;
col[0] = 0;
val[0] = 1;
col[1] = -static_cast<int>(n * n);
col[2] = -static_cast<int>(n);
col[3] = -1;
col[4] = 0;
col[5] = 1;
col[6] = n;
col[7] = (n * n);
val[1] = -h2i;
val[2] = -h2i;
val[3] = -h2i;
val[4] = h2i * 6;
val[5] = -h2i;
val[6] = -h2i;
val[7] = -h2i;
for(size_t k = 0; k < n; k++) {
for(size_t j = 0; j < n; j++) {
for(size_t i = 0; i < n; i++) {
if (
i == 0 || i == (n - 1) ||
j == 0 || j == (n - 1) ||
k == 0 || k == (n - 1)
)
{
idx.push_back(0);
} else {
idx.push_back(1);
}
}
}
}
size_t nnz = 6 * (n - 2) * (n - 2) * (n - 2) + n * n * n;
// Transfer data to compute devices.
vex::SpMatCCSR<real,int> A(ctx.queue(0), n * n * n, 2,
idx.data(), row.data(), col.data(), val.data());
std::vector<vex::command_queue> q1(1, ctx.queue(0));
vex::vector<real> x(q1, X);
vex::vector<real> y(q1, Y);
// Get timings.
y += A * x;
y = 0;
prof.tic_cpu("OpenCL");
for(size_t i = 0; i < M; i++)
y += A * x;
ctx.finish();
time_elapsed = prof.toc("OpenCL");
double gflops = (2.0 * nnz + N) * M / time_elapsed / 1e9;
double bwidth = M * (nnz * (2 * sizeof(real) + sizeof(int)) + 4 * N * sizeof(real)) / time_elapsed / 1e9;
std::cout
<< "SpMV (CCSR) (" << vex::type_name<real>() << ")\n"
<< " OpenCL"
<< "\n GFLOPS: " << gflops
<< "\n Bandwidth: " << bwidth
<< std::endl;
if (options.bm_cpu) {
prof.tic_cpu("C++");
for(size_t k = 0; k < M; k++)
for(size_t i = 0; i < N; i++) {
real s = 0;
for(size_t j = row[idx[i]]; j < row[idx[i] + 1]; j++)
s += val[j] * X[i + col[j]];
//.........这里部分代码省略.........