{ int num_steps = 1000000; double step = 1.0/num_steps; int i = get_global_id(0); double x = (i - 0.5) * step; integrals[i] = 4.0 / (1.0 + x * x); }""" context = cl.create_some_context() # Print out device info deviceinfo.output_device_info(context.devices[0]) # Create a command queue queue = cl.CommandQueue(context) # Create the compute program from the source buffer # and build it program = cl.Program(context, kernelsource).build() #Create empty vector of h_i that will be used to store the output h_i = numpy.empty(LENGTH).astype(numpy.float32) # Create the output (i) array in device memory d_i = cl.Buffer(context, cl.mem_flags.READ_WRITE, h_i.nbytes)
int i = get_global_id(0); if (i < count) c[i] = a[i] + b[i]; } """ #------------------------------------------------------------------------------ # Main procedure # Create a compute context # Ask the user to select a platform/device on the CLI context = cl.create_some_context() # Print out device info deviceinfo.output_device_info(context.devices[0]) # Create a command queue queue = cl.CommandQueue(context) # Create the compute program from the source buffer # and build it program = cl.Program(context, kernelsource).build() # Create a and b vectors and fill with random float values h_a = numpy.random.rand(LENGTH).astype(numpy.float32) h_b = numpy.random.rand(LENGTH).astype(numpy.float32) # Create an empty c vector (a+b) to be returned from the compute device h_c = numpy.empty(LENGTH).astype(numpy.float32) # Create the input (a, b) arrays in device memory and copy data from host