Last active
September 23, 2017 11:26
-
-
Save ryanrhymes/6c1cb6da4bbe86bee893096c66b0dc94 to your computer and use it in GitHub Desktop.
opencl experiment
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
#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;; |
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
#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