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; }
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; }
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; }
TEST(testqueues, main) { cout << "start" << endl; if(!EasyCL::isOpenCLAvailable()) { cout << "opencl library not found" << endl; exit(-1); } cout << "found opencl library" << endl; EasyCL *cl = EasyCL::createForFirstGpuOtherwiseCpu(); CLQueue *queue2 = cl->newQueue(); CLQueue *queue3 = cl->newQueue(); CLKernel *kernel = cl->buildKernelFromString(getKernel(), "test", ""); // CLKernel *kernel2 = cl->buildKernelFromString(queue, 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); assertEquals(out[0] , 7); assertEquals(out[1] , 10); assertEquals(out[2] , 13); assertEquals(out[3] , 16); assertEquals(out[4] , 19); // in[5]; for(int i = 0; i < 5; i++) { in[i] = i * 3; out[i] = 0; } // float out[5]; kernel->input(5, in); kernel->output(5, out); // size_t global = 5; // size_t local = 5; kernel->run(queue2, 1, &global, &local); assertEquals(out[0] , 7); assertEquals(out[1] , 10); assertEquals(out[2] , 13); assertEquals(out[3] , 16); assertEquals(out[4] , 19); // in[5]; for(int i = 0; i < 5; i++) { in[i] = i * 3; out[i] = 0; } // float out[5]; kernel->input(5, in); kernel->output(5, out); // size_t global = 5; // size_t local = 5; kernel->run(queue3, 1, &global, &local); assertEquals(out[0] , 7); assertEquals(out[1] , 10); assertEquals(out[2] , 13); assertEquals(out[3] , 16); assertEquals(out[4] , 19); // in[5]; for(int i = 0; i < 5; i++) { in[i] = i * 3; out[i] = 0; } // float out[5]; kernel->input(5, in); kernel->output(5, out); // size_t global = 5; // size_t local = 5; kernel->run(1, &global, &local); assertEquals(out[0] , 7); assertEquals(out[1] , 10); assertEquals(out[2] , 13); assertEquals(out[3] , 16); assertEquals(out[4] , 19); // in[5]; for(int i = 0; i < 5; i++) { in[i] = i * 3; out[i] = 0; } // float out[5]; kernel->input(5, in); kernel->output(5, out); // size_t global = 5; // size_t local = 5; kernel->run(queue2, 1, &global, &local); assertEquals(out[0] , 7); assertEquals(out[1] , 10); assertEquals(out[2] , 13); assertEquals(out[3] , 16); assertEquals(out[4] , 19); delete queue2; delete queue3; cout << "tests completed ok" << endl; }