Module Streamlines.Pocl

Pocl - OpenCL abstraction layer, as a workflow (but using global properties)

Copyright (C) 2017-2018,  Colin P Stark and Gavin J Stark.  All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @file   pocl.ml
 * @brief  OpenCL support library
 *
module ODM = Owl.Dense.Matrix.Generic
module ODN = Owl.Dense.Ndarray.Generic
module Option = Batteries.Option

Types

type t = {
props : Properties.t_props_pocl;
mutable platform : Owl_opencl_generated.cl_platform_id option;
mutable device : Owl_opencl_generated.cl_device_id option;
mutable context : Owl_opencl_generated.cl_context option;
mutable queue : Owl_opencl_generated.cl_command_queue option;
}

t

Structure for the Pocl processing

type t_buffer = Owl_opencl_generated.cl_mem

t_buffer

OpenCL buffer type, rename that from Owl.

val cl_platform : t ‑> Owl_opencl_generated.cl_platform_id

cl_platform t

Retrieve OpenCL platform id from a Pocl.t

val cl_device : t ‑> Owl_opencl_generated.cl_device_id

cl_device t

Retrieve OpenCL device id from a Pocl.t

val cl_context : t ‑> Owl_opencl_generated.cl_context

cl_context t

Retrieve OpenCL context from a Pocl.t

val cl_queue : t ‑> Owl_opencl_generated.cl_command_queue

cl_queue t

Retrieve OpenCL queue from a Pocl.t

pv_verbosity functions

val pv_noisy : t ‑> (unit ‑> unit) ‑> unit

pv_noisy t

Shortcut to use Pocl.t verbosity for Properties.pv_noisy

val pv_debug : t ‑> (unit ‑> unit) ‑> unit

pv_debug t

Shortcut to use Pocl.t verbosity for Properties.pv_debug

val pv_info : t ‑> (unit ‑> unit) ‑> unit

pv_info t

Shortcut to use Pocl.t verbosity for Properties.pv_info

val pv_verbose : t ‑> (unit ‑> unit) ‑> unit

pv_verbose t

Shortcut to use Pocl.t verbosity for Properties.pv_verbose

Show functions

val show_device : int ‑> int ‑> Owl_opencl_generated.cl_device_id ‑> unit

show_device pi di d

Show OpenCL information for platform index pi and device d (index di)

val show_platform : int ‑> Owl_opencl_generated.cl_platform_id ‑> unit

show_platform pi p

Show OpenCL information and all devices for platform p

val show_system : unit ‑> unit

show_system ()

Show OpenCL information for all platforms and all devices

val show_context : Owl_opencl_generated.cl_context ‑> unit

show_context ctxt

Show OpenCL information for a context

val show_program : Owl_opencl_generated.cl_program ‑> unit

show_program program

Show OpenCL information for a program

val show_kernel : Owl_opencl_generated.cl_kernel ‑> unit

show_kernel kernel

Show OpenCL information for a kernel

val show_queue : Owl_opencl_generated.cl_command_queue ‑> unit

show_queue queue

Show OpenCL information for a queue

Program and kernel building functions

val debug_build : Owl_opencl.G.cl_program ‑> Owl_opencl.G.cl_device_id ‑> unit

debug_build program device

display debug output for a built program on a device

val make_program : t ‑> string ‑> string ‑> Owl_opencl_generated.cl_program

make_program t source compile_options

Compile source with compile_options using the platform, device, and context specified by the Pocl.t t.

Provide verbose information if required.

On failure, output debug information for the program and raise an exception

val get_kernel : 'a ‑> Owl_opencl_generated.cl_program ‑> string ‑> Owl_opencl_generated.cl_kernel

get_kernel pocl program name

Get the kernel of the given name from the compiled program

val make_queue : t ‑> Owl_opencl_generated.cl_command_queue

make_queue t

Make an OpenCL queue for the context and device in the Pocl.t

Buffer handling functions

val buffer_of_array : ?⁠copy:bool ‑> t ‑> bool ‑> 'c ‑> ('a'b, Bigarray.c_layout) Bigarray.Genarray.t ‑> Owl_opencl_generated.cl_mem

buffer_of_array ?copy t kernel_read kernel_write ba

Create an OpenCL buffer from a given bigarray, with appropriate read/write/copy settings

val copy_buffer_to_gpu : t ‑> src:('a'b, Bigarray.c_layout) Bigarray.Genarray.t ‑> dst:Owl_opencl.G.cl_mem ‑> unit

copy_buffer_to_gpu t src dst

Copy data from a bigarray src to an OpenCL buffer dst, using the queue of the Pocl.t

The event indicating completion is ignored; the method used in this code is to wait for the queue to finish to guarantee completion of the buffer copy.

val copy_buffer_from_gpu : t ‑> src:Owl_opencl.G.cl_mem ‑> dst:('a'b, Bigarray.c_layout) Bigarray.Genarray.t ‑> unit

copy_buffer_from_gpu t src dst

Copy data from an OpenCL buffer src to a bigarray dst, using the queue of the Pocl.t

The event indicating completion is ignored; the method used in this code is to wait for the queue to finish to guarantee completion of the buffer copy.

Queue, event handling and kernel execution

val finish_queue : t ‑> unit

finish_queue t

Wait for the queue in the Pocl.t to finish (kernels to execute, copies to complete, etc)

val kernel_set_arg_buffer : t ‑> Owl_opencl_generated.cl_kernel ‑> int ‑> Owl_opencl.G.cl_mem ‑> unit

kernel_set_arg_buffer t kernel index buffer

Set kernel argument index to be the OpenCL buffer

val enqueue_kernel : t ‑> Owl_opencl_generated.cl_kernel ‑> int list ‑> Owl_opencl_generated.cl_event

enqueue_kernel t kernel global_work_size

Enqueue a kernel with a specified work size, to the queue of the Pocl.t.

val event_wait : 'a ‑> Owl_opencl_generated.cl_event ‑> unit

event_wait t event

Wait for an event

External creation/build functions

val compile_program : t ‑> string ‑> string ‑> Owl_opencl_generated.cl_program

compile_program t source compile_options

Compile an OpenCL program on the device/context of the Pocl.t using the specified source (text) and compilation options

val get_memory_limit : t ‑> int

get_memory_limit t

Get the memory limit for the device of the Pocl.t

val compile_options : 'a ‑> Core.t_core_data ‑> Core.Info.t ‑> string ‑> string

compile_options t data info_struct kernel_name

Convert the info struct into a list of '-D' compiler macros.

This uses the kernel_name (as this is passed in as a define).

val append_in_file : (string * int) ‑> string ‑> Pervasives.in_channel ‑> string * int

append_in_file (source, source_lines) filename f

Internal function; appends the contents of f (the contents of filename) to source, adding after blank lines a comment line with the filename and source line number, so that OpenCL compilation errors may be readily discovered.

The function is designed to be used in folding over a list of source code files.

val read_source : string list ‑> string list ‑> string

read_source path cl_files

Read in a list of source code (OpenCL) files, returning a string containing the source. The source code lines are annotated where sensible with filename and line numbers, to ease finding errors and warnings in OpenCL compilation.

val rebuild_info_struct : t ‑> Core.t_core_data ‑> Core.Info.t ‑> unit

rebuild_info_struct pocl data info_struct

Rebuild an info struct from properties.

val prepare_cl_context_queue : t ‑> unit

prepare_cl_context_queue t

Prepare an OpenCL context using the properties in the Pocl.t

If the requested platform is not valid on the system then platform 0 is used instead

val create : Properties.t_props ‑> t

create props

Create the Pocl.t structure from a given set of properties. The OpenCL platform, device, context etc. are created by a later call to prepare_cl_context_queue.