Created
January 23, 2010 20:25
-
-
Save rubenfonseca/284779 to your computer and use it in GitHub Desktop.
OpenCL Macruby Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OpenCL.devices.each do |device| | |
info = device.info | |
puts "Trying on #{info[:name]} #{info[:vendor]} #{info[:version]} [#{info[:type]}]" | |
context = device.create_context | |
queue = context.create_command_queue | |
program = context.create_program <<EOF | |
// OpenCL kernel that computes the square of an input array | |
__kernel square( | |
__global float* input, | |
__global float* output, | |
__global int count) | |
{ | |
int i = get_global_id(0); | |
if(i < count) | |
output[i] = input[i] * input[i]; | |
} | |
EOF | |
kernel = program.create_kernel("square") | |
input = context.create_read_buffer(32768) | |
output = context.create_write_buffer(32768) | |
input.write(queue, (1..32768).to_a) | |
kernel.set_arg(0, input) | |
kernel.set_arg(1, output) | |
kernel.set_arg(2, 32768) | |
kernel.enqueue_nd_range(device, queue, 32768) | |
puts output.read(queue).last | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment