本文整理汇总了C++中CLWrapper::copyTo方法的典型用法代码示例。如果您正苦于以下问题:C++ CLWrapper::copyTo方法的具体用法?C++ CLWrapper::copyTo怎么用?C++ CLWrapper::copyTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CLWrapper
的用法示例。
在下文中一共展示了CLWrapper::copyTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exit
TEST(testcopybuffer, throwsifnotondevice) {
if(!EasyCL::isOpenCLAvailable()) {
cout << "opencl library not found" << endl;
exit(-1);
}
cout << "found opencl library" << endl;
EasyCL *cl = EasyCL::createForFirstGpuOtherwiseCpu();
//CLKernel *kernel = cl->buildKernel("testeasycl.cl", "test");
const int bufferSize = 100 * 1024 / 4;
float *in = new float[bufferSize];
float *in2 = new float[bufferSize];
for(int i = 0; i < bufferSize; i++) {
in[i] = i * 3;
in2[i] = 23 + i;
}
CLWrapper *inwrapper = cl->wrap(bufferSize, in);
CLWrapper *in2wrapper = cl->wrap(bufferSize, in2);
inwrapper->copyToDevice();
// in2wrapper->copyToDevice();
bool threw = false;
try {
inwrapper->copyTo(in2wrapper);
} catch(runtime_error &e) {
threw = true;
}
EXPECT_TRUE(threw);
delete cl;
}
示例2: exit
TEST(testcopybuffer, main) {
if(!EasyCL::isOpenCLAvailable()) {
cout << "opencl library not found" << endl;
exit(-1);
}
cout << "found opencl library" << endl;
EasyCL *cl = EasyCL::createForFirstGpuOtherwiseCpu();
//CLKernel *kernel = cl->buildKernel("testeasycl.cl", "test");
float in[5];
float in2[5];
for(int i = 0; i < 5; i++) {
in[i] = i * 3.0f;
in2[i] = 23.0f + i;
}
float out[5];
CLWrapper *inwrapper = cl->wrap(5, in);
CLWrapper *in2wrapper = cl->wrap(5, in2);
CLWrapper *outwrapper = cl->wrap(5, out);
inwrapper->copyToDevice();
in2wrapper->copyToDevice();
EXPECT_FALSE(in2wrapper->isDeviceDirty());
inwrapper->copyTo(in2wrapper);
EXPECT_TRUE(in2wrapper->isDeviceDirty());
// cl->finish();
// check that in2 host-side unchanged:
for(int i = 0; i < 5; i++) {
in[i] = i * 3.0f;
EXPECT_EQ(23.0f + i, in2[i]);
}
in2wrapper->copyToHost();
// check that in2 is now a copy of in:
for(int i = 0; i < 5; i++) {
in[i] = i * 3.0f;
EXPECT_EQ(i * 3.0f, in2[i]);
}
// check that modifying in2 doesnt modfiy in:
in2[1] = 27;
in2wrapper->copyToDevice();
inwrapper->copyToHost();
EXPECT_EQ(1 * 3.0f, in[1]);
in2wrapper->copyToHost();
EXPECT_EQ(1 * 3.0f, in[1]);
EXPECT_EQ(27.0f, in2[1]);
delete inwrapper;
delete in2wrapper;
delete outwrapper;
delete cl;
}