Skip to content

Instantly share code, notes, and snippets.

@ryanrhymes
Last active September 23, 2017 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanrhymes/6c1cb6da4bbe86bee893096c66b0dc94 to your computer and use it in GitHub Desktop.
Save ryanrhymes/6c1cb6da4bbe86bee893096c66b0dc94 to your computer and use it in GitHub Desktop.
opencl experiment
#require "owl_opencl";;
let prog_s = "
__kernel void hello_kernel(__global const float *a,
__global const float *b,
__global float *result)
{
int gid = get_global_id(0);
result[gid] = a[gid] + b[gid];
}
";;
let l = Owl_opencl.Platform.get_platforms ();;
let p = Owl_opencl.Platform.get_info l.(0);;
let m = Owl_opencl.Device.get_devices l.(0);;
let d = Owl_opencl.Device.get_info m.(0);;
let ctx = Owl_opencl.Context.create m;;
let ctx_info = Owl_opencl.Context.get_info ctx;;
let program = Owl_opencl.Program.create_with_source ctx [|prog_s|];;
Owl_opencl.Program.build program m;;
let program_info = Owl_opencl.Program.get_info program;;
let kernel = Owl_opencl.Kernel.create program "hello_kernel";;
Owl_opencl.Kernel.get_info kernel;;
let cmdq = Owl_opencl.CommandQueue.create ctx m.(0);;
Owl_opencl.CommandQueue.get_info cmdq;;
let x = Arr.uniform [|10;10;10|];;
let buf = Owl_opencl.Buffer.create ~flags:[|Owl_opencl_generated.cl_MEM_USE_HOST_PTR|] ctx x;;
#require "owl_opencl";;
let prog_s = "
__kernel void hello_kernel(__global const float *a,
__global const float *b,
__global float *result)
{
int gid = get_global_id(0);
result[gid] = a[gid] + b[gid];
}
";;
let l = Owl_opencl.Platform.get_platforms ();;
let m = Owl_opencl.Device.get_devices l.(0);;
let gpu = [|m.(1)|];;
let ctx = Owl_opencl.Context.create gpu;;
let cmdq = Owl_opencl.CommandQueue.create ctx gpu;;
let program = Owl_opencl.Program.create_with_source ctx [|prog_s|];;
Owl_opencl.Program.build program gpu;;
let kernel = Owl_opencl.Kernel.create program "hello_kernel";;
let a = Dense.Ndarray.S.uniform [|1024|];;
let b = Dense.Ndarray.S.uniform [|1024|];;
let a' = Owl_opencl.Buffer.create ~flags:[|Owl_opencl_generated.cl_MEM_USE_HOST_PTR|] ctx a ;;
let b' = Owl_opencl.Buffer.create ~flags:[|Owl_opencl_generated.cl_MEM_USE_HOST_PTR|] ctx b ;;
Kernel.set_arg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment