Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Execute ¶
func Execute(program string, programName string, platform, device int, progArgs ...interface{}) ([]float32, error)
Execute executes a OpenCL program on the given arguments
Example (Add) ¶
var kernelSource = ` __kernel void square( __global float * in, const unsigned int count, __global float * out) { int i = get_global_id(0); if (i < count) out[i] = in[i] * in[i]; } ` input := []float32{0.5, 1.5, 1.0, 2.0} // Parameters: OpenCL Code, Name of function, platform num, device num, parameters for function results, err := Execute(kernelSource, "square", 0, 0, input, uint32(len(input))) if err != nil { panic(err) } fmt.Println(results)
Output: [0.25 2.25 1 4]
Example (Squares) ¶
var kernelSource = ` __kernel void square( __global float * in, const unsigned int count, __global float * out) { int i = get_global_id(0); if (i < count) out[i] = in[i] * in[i]; } ` input := []float32{0.5, 1.5, 1.0, 2.0} // Parameters: OpenCL Code, Name of function, platform num, device num, parameters for function results, err := Execute(kernelSource, "square", 0, 0, input, uint32(len(input))) if err != nil { panic(err) } fmt.Println(results)
Output: [0.25 2.25 1 4]
func ExecuteImage ¶
func ExecuteImage(program string, programName string, platform, device int, progArgs ...interface{}) (*image.RGBA, error)
ExecuteImage executes a OpenCL program on the given arguments, which should be an image
Example (Invert) ¶
var kernelSource = ` __kernel void invert( __read_only image2d_t in, const int width, const int height, __write_only image2d_t out) { const int2 pos = (int2)(get_global_id(0), get_global_id(1)); float4 pixel = (float4)(0); if ((pos.x < width) && (pos.y < height)) { pixel = read_imagef(in, pos); pixel = (float4)(1) - pixel; write_imagef(out, pos, pixel); } }` // Created all-black image, 7x7 inImg := image.NewRGBA(image.Rect(0, 0, 7, 7)) b := inImg.Bounds() // Calculate, now you have all-white image outImg, err := ExecuteImage(kernelSource, "invert", 0, 0, inImg, int32(b.Dx()), int32(b.Dy())) if err != nil { panic(err) } fmt.Println(outImg.Pix)
Output: [255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255]
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.