当前位置: 首页>>代码示例>>C++>>正文


C++ CLKernel::run方法代码示例

本文整理汇总了C++中CLKernel::run方法的典型用法代码示例。如果您正苦于以下问题:C++ CLKernel::run方法的具体用法?C++ CLKernel::run怎么用?C++ CLKernel::run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CLKernel的用法示例。


在下文中一共展示了CLKernel::run方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: exit

TEST(testqueues, defaultqueue) {
    cout << "start" << endl;
    if(!EasyCL::isOpenCLAvailable()) {
        cout << "opencl library not found" << endl;
        exit(-1);
    }
    cout << "found opencl library" << endl;

    EasyCL *cl = EasyCL::createForFirstGpuOtherwiseCpu();

    CLKernel *kernel = cl->buildKernelFromString(getKernel(), "test", "");

    float in[5];
    float out[5];
    for(int i = 0; i < 5; i++) {
        in[i] = i * 3;
        out[i] = 0;
    }
    kernel->input(5, in);
    kernel->output(5, out);
    size_t global = 5;
    size_t local = 5;
    kernel->run(1, &global, &local);
    cl->finish();
    assertEquals(out[0] , 7);
    assertEquals(out[1] , 10);
    assertEquals(out[2] , 13);
    assertEquals(out[3] , 16);
    assertEquals(out[4] , 19);

    for(int i = 0; i < 5; i++) {
        in[i] = i * 3;
        out[i] = 0;
    }

    cout << "cl->queue " << (void *)cl->queue << endl;
    cout << "*cl->queue " << (void *)*cl->queue << endl;
    cout << "cl->default_queue->queue" << (void *)cl->default_queue->queue << endl;
    kernel->input(5, in);
    kernel->output(5, out);
    kernel->run(cl->default_queue, 1, &global, &local);
    cl->finish();
    assertEquals(out[0] , 7);
    assertEquals(out[1] , 10);
    assertEquals(out[2] , 13);
    assertEquals(out[3] , 16);
    assertEquals(out[4] , 19);

    cout << "tests completed ok" << endl;
}
开发者ID:hughperkins,项目名称:EasyCL,代码行数:50,代码来源:testqueues.cpp

示例2: exit

TEST(testinout, main) {
    if(!EasyCL::isOpenCLAvailable()) {
        cout << "opencl library not found" << endl;
        exit(-1);
    }
    cout << "found opencl library" << endl;

    EasyCL *cl = EasyCL::createForFirstGpuOtherwiseCpu();
    CLKernel *kernel = cl->buildKernelFromString(getKernel(), "test", "");
    float inout[5];
    for(int i = 0; i < 5; i++) {
        inout[i] = i * 3;
    }
    kernel->inout(5, inout);
    size_t global = 5;
    size_t local = 5;
    kernel->run(1, &global, &local);
    assertEquals(inout[0] , 7);
    assertEquals(inout[1] , 10);
    assertEquals(inout[2] , 13);
    assertEquals(inout[3] , 16);
    assertEquals(inout[4] , 19);
    cout << "tests completed ok" << endl;

    delete kernel;
    delete cl;
}
开发者ID:BenBBear,项目名称:EasyCL,代码行数:27,代码来源:testinout.cpp

示例3: main

int main(int argc, char *argv[]) 
{
	const int test_size = 128;

	std::random_device rd;
	std::seed_seq s{ rd(), rd(), rd(), rd(), rd(), rd(), rd(), rd() };
	std::mt19937 mt(s);

	EasyCL *cl = EasyCL::createForFirstGpuOtherwiseCpu();

	CLKernel *kern = cl->buildKernel("test.cl", "test");

	std::vector<uint32_t> inbuf(test_size*4), outbuf(test_size), compare(test_size);
	std::generate(inbuf.begin(), inbuf.end(), mt);

	std::cout << "Running CL implementation" << std::endl;
	kern->in(inbuf.size(), &inbuf[0]);
	kern->out(outbuf.size(), &outbuf[0]);
	size_t global_size[] = { test_size };
	kern->run(1, global_size, nullptr);
	delete kern;

	std::cout << "Running local implementation" << std::endl;
	for (int i = 0; i < compare.size(); ++i) {
		compare[i] = inbuf[i] ^ inbuf[i + 1] ^ inbuf[i + 2] ^ inbuf[i + 3];
	}

	std::cout << "Comparing CL test with local implementation" << std::endl;
	for (int i = 0; i < compare.size(); ++i) {
		if (outbuf[i] != compare[i]) {
			std::cout << "Error in index " << i << " " << outbuf[i] << " != " << compare[i] << std::endl;
		}
	}

	return 0;
}
开发者ID:ajmadsen,项目名称:OpenCLTest,代码行数:36,代码来源:Main.cpp


注:本文中的CLKernel::run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。