示例#1
0
def testOpenCL(ctx, queue):
    passed = numpy.array([0])
    debugTest = Debug()
    mf = cl.mem_flags
    passed_buf = cl.Buffer(ctx, mf.WRITE_ONLY, passed.nbytes)
    debugTest_buf = cl.Buffer(ctx, mf.WRITE_ONLY, sizeof(debugTest))

    program = oclu.loadProgram(ctx, "OpenCL/RayTracingTests.cl")

    # Test in OpenCL
    program.test(queue, (1,), None, passed_buf, debugTest_buf)
    cl.enqueue_copy(queue, passed, passed_buf).wait()
    cl.enqueue_copy(queue, debugTest, debugTest_buf).wait()

    if numpy.allclose(passed, numpy.array([1])):
        print "OpenCL ray-tracing unit tests PASSED"
    else:
        print "OpenCL ray-tracing unit tests FAILED"
示例#2
0
problemSize = 20000000

ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)

a = numpy.array(range(problemSize), dtype=numpy.int32)
b = numpy.array(range(problemSize), dtype=numpy.int32)
resultOpenCL = numpy.empty_like(a)
resultPython = numpy.empty_like(a)

mf = cl.mem_flags
a_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a)
b_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=b)
resultOpenCL_buf = cl.Buffer(ctx, mf.WRITE_ONLY, a.nbytes)

program = oclu.loadProgram(ctx, "Program1.cl")

# Run in OpenCL
time1 = time()
program.calculate(queue, a.shape, None, a_buf, b_buf, resultOpenCL_buf)
cl.enqueue_copy(queue, resultOpenCL, resultOpenCL_buf).wait()
timeOpenCL = time()-time1

# Run in Python
time1 = time()
resultPython = a * 2 + b * 2
resultPython += a * 2 + b * 2
resultPython -= a * 3 + b * 3
#for i in range(problemSize):
#    resultPython[i] = a[i] * 2 + b[i] * 2
#    resultPython[i] += a[i] * 2 + b[i] * 2