Did you know ... Search Documentation:
Pack array -- prolog/array.pl
PublicShow source

A program is a sequence of boxes, over/2: each box runs its equations at every point of its axes, like a loop nest, and an equation writes one element of an array, a name. From the boxes the compiler derives the kernels, which axes are parallel, what fuses, what lives in registers or local memory, and runs them on any OpenCL device; eval/3 runs the same boxes in Prolog, exactly, the reference to check a device against. Shapes and subscripts are clpBNR constraints, so an extent may stay unknown: one compiled program serves every size, and a subscript out of bounds is an error before anything runs.

% C = A B, for A of N x M and B of M x P.
matmul(A, B, C, N, M, P) :-
   shape(A, [N, M]), shape(B, [M, P]), shape(C, [N, P]),
   over([I:N, J:P], [C[I, J] := 0]),
   over([I:N, J:P, K:M], [C[I, J] := C[I, J] + A[I, K] * B[K, J]]).

?- matmul(A, B, C, 2, 3, 2),
   Data = [A-[1, 2, 3, 4, 5, 6], B-[1, 0, 0, 1, 1, 1]],
   eval(C, Data, Ref),
   run(C, Data, Values, [device(pocl)]).
Ref = Values, Values = [4.0, 5.0, 10.0, 11.0].

The user-facing predicates of the pack, from the modules under array/:

The modules under array/ export more, for tools and tests: load them by name. So are array/api, the functional overlay `Y @= Expr`, and array/grad, the derivatives of a program.

The pack writes caches under $XDG_CACHE_HOME or ~/.cache, each safe to delete: array_eval, the compiled reference programs of eval/3, the flag eval_cache_directory; array_cl, the binaries of OpenCL programs, the flag cl_program_cache_directory; and array_tune, the options tune_device/2 measured for a device, the flag array_tune_file.

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 shape(Arg1, Arg2)
 elements(Arg1, Arg2)
 kind(Arg1, Arg2)
 Arg1 type Arg2
 label_kinds(Arg1)
 label_types(Arg1)
 power_of_two(Arg1)
 permutation(Arg1)
 over(Arg1, Arg2)
 copy(Arg1, Arg2, Arg3)
 device(Arg1, Arg2)
 value(Arg1, Arg2)
 unrealize(Arg1)
 program(Arg1, Arg2)
 eval(Arg1, Arg2, Arg3)
 kernels(Arg1, Arg2, Arg3)
 source(Arg1, Arg2)
 device_options(Arg1, Arg2)
 compile(Arg1, Arg2, Arg3)
 compile(Arg1, Arg2)
 compile_all(Arg1, Arg2, Arg3)
 run(Arg1, Arg2, Arg3)
 signature(Arg1, Arg2, Arg3)
 release(Arg1)
 run(Arg1, Arg2, Arg3, Arg4)
 run_all(Arg1, Arg2, Arg3, Arg4)
 realize(Arg1, Arg2, Arg3)
 flush_handles
 signature_all(Arg1, Arg2, Arg3, Arg4)
 opencl_device(Arg1, Arg2)
 print_array(Arg1)
 print_array(Arg1, Arg2)