2010-03-03 03:02:47 -05:00
|
|
|
! Copyright (C) 2010 Erik Charlebois.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2010-12-25 19:54:45 -05:00
|
|
|
USING: accessors alien alien.c-types alien.data arrays
|
|
|
|
byte-arrays combinators combinators.smart destructors
|
2020-02-12 20:00:19 -05:00
|
|
|
io.encodings.ascii io.encodings.string kernel libc literals
|
|
|
|
locals make math namespaces opencl.ffi sequences
|
|
|
|
specialized-arrays variants ;
|
2010-03-03 03:02:47 -05:00
|
|
|
IN: opencl
|
|
|
|
SPECIALIZED-ARRAYS: void* char size_t ;
|
|
|
|
|
|
|
|
<PRIVATE
|
2015-07-14 23:45:13 -04:00
|
|
|
|
2010-03-03 03:02:47 -05:00
|
|
|
ERROR: cl-error err ;
|
|
|
|
|
|
|
|
: cl-success ( err -- )
|
2015-08-13 19:13:05 -04:00
|
|
|
dup CL_SUCCESS = [ drop ] [ cl-error ] if ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: cl-not-null ( err -- )
|
2015-08-13 19:13:05 -04:00
|
|
|
dup f = [ cl-error ] [ drop ] if ; inline
|
2015-06-29 19:43:15 -04:00
|
|
|
|
2010-04-14 03:08:10 -04:00
|
|
|
: info-data-size ( handle name info-quot -- size_t )
|
2018-06-19 20:15:05 -04:00
|
|
|
[ 0 f 0 size_t <ref> ] dip
|
|
|
|
[ call cl-success ] keepd size_t deref ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
2010-04-14 03:08:10 -04:00
|
|
|
: info-data-bytes ( handle name info-quot size -- bytes )
|
2018-06-19 20:15:05 -04:00
|
|
|
swap [ dup <byte-array> f ] dip [ call cl-success ] keepdd ; inline
|
2010-04-14 03:08:10 -04:00
|
|
|
|
|
|
|
: info ( handle name info-quot lift-quot -- value )
|
|
|
|
[ 3dup info-data-size info-data-bytes ] dip call ; inline
|
|
|
|
|
|
|
|
: 2info-data-size ( handle1 handle2 name info-quot -- size_t )
|
2018-06-19 20:15:05 -04:00
|
|
|
[ 0 f 0 size_t <ref> ] dip
|
|
|
|
[ call cl-success ] keepd size_t deref ; inline
|
2010-04-14 03:08:10 -04:00
|
|
|
|
|
|
|
: 2info-data-bytes ( handle1 handle2 name info-quot size -- bytes )
|
2018-06-19 20:15:05 -04:00
|
|
|
swap [ dup <byte-array> f ] dip [ call cl-success ] keepdd ; inline
|
2010-04-14 03:08:10 -04:00
|
|
|
|
|
|
|
: 2info ( handle1 handle2 name info_quot lift_quot -- value )
|
|
|
|
[ 4dup 2info-data-size 2info-data-bytes ] dip call ; inline
|
2012-07-19 14:24:45 -04:00
|
|
|
|
2010-03-03 03:02:47 -05:00
|
|
|
: info-bool ( handle name quot -- ? )
|
2010-10-20 18:42:53 -04:00
|
|
|
[ uint deref CL_TRUE = ] info ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: info-ulong ( handle name quot -- ulong )
|
2010-10-20 18:42:53 -04:00
|
|
|
[ ulonglong deref ] info ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: info-int ( handle name quot -- int )
|
2010-10-20 18:42:53 -04:00
|
|
|
[ int deref ] info ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: info-uint ( handle name quot -- uint )
|
2010-10-20 18:42:53 -04:00
|
|
|
[ uint deref ] info ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: info-size_t ( handle name quot -- size_t )
|
2010-10-20 18:42:53 -04:00
|
|
|
[ size_t deref ] info ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: 2info-size_t ( handle1 handle2 name quot -- size_t )
|
2010-10-20 18:42:53 -04:00
|
|
|
[ size_t deref ] 2info ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: info-string ( handle name quot -- string )
|
2013-11-24 23:42:10 -05:00
|
|
|
[ ascii decode but-last ] info ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: 2info-string ( handle name quot -- string )
|
2013-11-24 23:42:10 -05:00
|
|
|
[ ascii decode but-last ] 2info ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: info-size_t-array ( handle name quot -- size_t-array )
|
2011-09-25 14:49:27 -04:00
|
|
|
[ [ length size_t heap-size / ] keep swap size_t <c-direct-array> ] info ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
TUPLE: cl-handle < disposable handle ;
|
2015-02-08 18:45:42 -05:00
|
|
|
|
2010-03-03 03:02:47 -05:00
|
|
|
PRIVATE>
|
|
|
|
|
2010-03-03 05:06:58 -05:00
|
|
|
VARIANT: cl-device-type
|
|
|
|
cl-device-default cl-device-cpu cl-device-gpu cl-device-accelerator ;
|
|
|
|
|
|
|
|
: size_t>cl-device-type ( size_t -- cl-device-type )
|
|
|
|
{
|
|
|
|
{ CL_DEVICE_TYPE_DEFAULT [ cl-device-default ] }
|
|
|
|
{ CL_DEVICE_TYPE_CPU [ cl-device-cpu ] }
|
|
|
|
{ CL_DEVICE_TYPE_GPU [ cl-device-gpu ] }
|
|
|
|
{ CL_DEVICE_TYPE_ACCELERATOR [ cl-device-accelerator ] }
|
|
|
|
} case ; inline
|
|
|
|
|
2010-03-03 03:02:47 -05:00
|
|
|
VARIANT: cl-fp-feature
|
|
|
|
cl-denorm cl-inf-and-nan cl-round-to-nearest cl-round-to-zero cl-round-to-inf cl-fma ;
|
|
|
|
|
|
|
|
VARIANT: cl-cache-type
|
|
|
|
cl-no-cache cl-read-only-cache cl-read-write-cache ;
|
|
|
|
|
|
|
|
VARIANT: cl-buffer-access-mode
|
|
|
|
cl-read-access cl-write-access cl-read-write-access ;
|
|
|
|
|
|
|
|
VARIANT: cl-image-channel-order
|
|
|
|
cl-channel-order-r cl-channel-order-a cl-channel-order-rg cl-channel-order-ra
|
|
|
|
cl-channel-order-rga cl-channel-order-rgba cl-channel-order-bgra cl-channel-order-argb
|
|
|
|
cl-channel-order-intensity cl-channel-order-luminance ;
|
|
|
|
|
|
|
|
VARIANT: cl-image-channel-type
|
|
|
|
cl-channel-type-snorm-int8 cl-channel-type-snorm-int16 cl-channel-type-unorm-int8
|
|
|
|
cl-channel-type-unorm-int16 cl-channel-type-unorm-short-565
|
|
|
|
cl-channel-type-unorm-short-555 cl-channel-type-unorm-int-101010
|
|
|
|
cl-channel-type-signed-int8 cl-channel-type-signed-int16 cl-channel-type-signed-int32
|
|
|
|
cl-channel-type-unsigned-int8 cl-channel-type-unsigned-int16
|
|
|
|
cl-channel-type-unsigned-int32 cl-channel-type-half-float cl-channel-type-float ;
|
|
|
|
|
|
|
|
VARIANT: cl-addressing-mode
|
|
|
|
cl-repeat-addressing cl-clamp-to-edge-addressing cl-clamp-addressing cl-no-addressing ;
|
|
|
|
|
|
|
|
VARIANT: cl-filter-mode
|
|
|
|
cl-filter-nearest cl-filter-linear ;
|
|
|
|
|
|
|
|
VARIANT: cl-command-type
|
|
|
|
cl-ndrange-kernel-command cl-task-command cl-native-kernel-command cl-read-buffer-command
|
|
|
|
cl-write-buffer-command cl-copy-buffer-command cl-read-image-command cl-write-image-command
|
|
|
|
cl-copy-image-command cl-copy-buffer-to-image-command cl-copy-image-to-buffer-command
|
|
|
|
cl-map-buffer-command cl-map-image-command cl-unmap-mem-object-command
|
|
|
|
cl-marker-command cl-acquire-gl-objects-command cl-release-gl-objects-command ;
|
|
|
|
|
|
|
|
VARIANT: cl-execution-status
|
|
|
|
cl-queued cl-submitted cl-running cl-complete cl-failure ;
|
|
|
|
|
|
|
|
TUPLE: cl-platform
|
|
|
|
id profile version name vendor extensions devices ;
|
|
|
|
|
|
|
|
TUPLE: cl-device
|
|
|
|
id type vendor-id max-compute-units max-work-item-dimensions
|
2015-06-29 19:43:15 -04:00
|
|
|
max-work-item-sizes max-work-group-size preferred-vector-width-char
|
|
|
|
preferred-vector-width-short preferred-vector-width-int
|
|
|
|
preferred-vector-width-long preferred-vector-width-float
|
|
|
|
preferred-vector-width-double max-clock-frequency address-bits
|
2010-03-03 03:02:47 -05:00
|
|
|
max-mem-alloc-size image-support max-read-image-args max-write-image-args
|
2015-06-29 19:43:15 -04:00
|
|
|
image2d-max-width image2d-max-height image3d-max-width image3d-max-height
|
2010-03-03 03:02:47 -05:00
|
|
|
image3d-max-depth max-samplers max-parameter-size mem-base-addr-align
|
|
|
|
min-data-type-align-size single-fp-config global-mem-cache-type
|
2015-06-29 19:43:15 -04:00
|
|
|
global-mem-cacheline-size global-mem-cache-size global-mem-size
|
|
|
|
max-constant-buffer-size max-constant-args local-mem? local-mem-size
|
|
|
|
error-correction-support profiling-timer-resolution endian-little
|
2010-03-03 03:02:47 -05:00
|
|
|
available compiler-available execute-kernels? execute-native-kernels?
|
|
|
|
out-of-order-exec-available? profiling-available?
|
|
|
|
name vendor driver-version profile version extensions ;
|
|
|
|
|
|
|
|
TUPLE: cl-context < cl-handle ;
|
|
|
|
TUPLE: cl-queue < cl-handle ;
|
|
|
|
TUPLE: cl-buffer < cl-handle ;
|
|
|
|
TUPLE: cl-sampler < cl-handle ;
|
|
|
|
TUPLE: cl-program < cl-handle ;
|
|
|
|
TUPLE: cl-kernel < cl-handle ;
|
|
|
|
TUPLE: cl-event < cl-handle ;
|
|
|
|
|
|
|
|
M: cl-context dispose* handle>> clReleaseContext cl-success ;
|
|
|
|
M: cl-queue dispose* handle>> clReleaseCommandQueue cl-success ;
|
|
|
|
M: cl-buffer dispose* handle>> clReleaseMemObject cl-success ;
|
|
|
|
M: cl-sampler dispose* handle>> clReleaseSampler cl-success ;
|
|
|
|
M: cl-program dispose* handle>> clReleaseProgram cl-success ;
|
|
|
|
M: cl-kernel dispose* handle>> clReleaseKernel cl-success ;
|
|
|
|
M: cl-event dispose* handle>> clReleaseEvent cl-success ;
|
|
|
|
|
|
|
|
TUPLE: cl-buffer-ptr
|
|
|
|
{ buffer cl-buffer read-only }
|
|
|
|
{ offset integer read-only } ;
|
|
|
|
C: <cl-buffer-ptr> cl-buffer-ptr
|
|
|
|
|
|
|
|
TUPLE: cl-buffer-range
|
|
|
|
{ buffer cl-buffer read-only }
|
|
|
|
{ offset integer read-only }
|
|
|
|
{ size integer read-only } ;
|
|
|
|
C: <cl-buffer-range> cl-buffer-range
|
|
|
|
|
|
|
|
SYMBOLS: cl-current-context cl-current-queue cl-current-device ;
|
|
|
|
|
|
|
|
<PRIVATE
|
2010-04-14 04:28:21 -04:00
|
|
|
|
2010-03-03 03:02:47 -05:00
|
|
|
: (current-cl-context) ( -- cl-context )
|
|
|
|
cl-current-context get ; inline
|
|
|
|
|
|
|
|
: (current-cl-queue) ( -- cl-queue )
|
|
|
|
cl-current-queue get ; inline
|
|
|
|
|
|
|
|
: (current-cl-device) ( -- cl-device )
|
|
|
|
cl-current-device get ; inline
|
|
|
|
|
|
|
|
GENERIC: buffer-access-constant ( buffer-access-mode -- n )
|
|
|
|
M: cl-read-write-access buffer-access-constant drop CL_MEM_READ_WRITE ;
|
|
|
|
M: cl-read-access buffer-access-constant drop CL_MEM_READ_ONLY ;
|
|
|
|
M: cl-write-access buffer-access-constant drop CL_MEM_WRITE_ONLY ;
|
|
|
|
|
|
|
|
GENERIC: buffer-map-flags ( buffer-access-mode -- n )
|
2020-02-12 20:00:19 -05:00
|
|
|
M: cl-read-write-access buffer-map-flags drop flags{ CL_MAP_READ CL_MAP_WRITE } ;
|
2010-03-03 03:02:47 -05:00
|
|
|
M: cl-read-access buffer-map-flags drop CL_MAP_READ ;
|
|
|
|
M: cl-write-access buffer-map-flags drop CL_MAP_WRITE ;
|
|
|
|
|
|
|
|
GENERIC: addressing-mode-constant ( addressing-mode -- n )
|
|
|
|
M: cl-repeat-addressing addressing-mode-constant drop CL_ADDRESS_REPEAT ;
|
|
|
|
M: cl-clamp-to-edge-addressing addressing-mode-constant drop CL_ADDRESS_CLAMP_TO_EDGE ;
|
|
|
|
M: cl-clamp-addressing addressing-mode-constant drop CL_ADDRESS_CLAMP ;
|
|
|
|
M: cl-no-addressing addressing-mode-constant drop CL_ADDRESS_NONE ;
|
|
|
|
|
|
|
|
GENERIC: filter-mode-constant ( filter-mode -- n )
|
|
|
|
M: cl-filter-nearest filter-mode-constant drop CL_FILTER_NEAREST ;
|
|
|
|
M: cl-filter-linear filter-mode-constant drop CL_FILTER_LINEAR ;
|
|
|
|
|
|
|
|
: cl_addressing_mode>addressing-mode ( cl_addressing_mode -- addressing-mode )
|
|
|
|
{
|
|
|
|
{ CL_ADDRESS_REPEAT [ cl-repeat-addressing ] }
|
|
|
|
{ CL_ADDRESS_CLAMP_TO_EDGE [ cl-clamp-to-edge-addressing ] }
|
|
|
|
{ CL_ADDRESS_CLAMP [ cl-clamp-addressing ] }
|
|
|
|
{ CL_ADDRESS_NONE [ cl-no-addressing ] }
|
2010-03-03 05:06:58 -05:00
|
|
|
} case ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: cl_filter_mode>filter-mode ( cl_filter_mode -- filter-mode )
|
|
|
|
{
|
|
|
|
{ CL_FILTER_LINEAR [ cl-filter-linear ] }
|
|
|
|
{ CL_FILTER_NEAREST [ cl-filter-nearest ] }
|
2010-03-03 05:06:58 -05:00
|
|
|
} case ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: platform-info-string ( handle name -- string )
|
2010-04-14 04:28:21 -04:00
|
|
|
[ clGetPlatformInfo ] info-string ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: platform-info ( id -- profile version name vendor extensions )
|
|
|
|
{
|
|
|
|
[ CL_PLATFORM_PROFILE platform-info-string ]
|
|
|
|
[ CL_PLATFORM_VERSION platform-info-string ]
|
|
|
|
[ CL_PLATFORM_NAME platform-info-string ]
|
|
|
|
[ CL_PLATFORM_VENDOR platform-info-string ]
|
2015-06-29 19:43:15 -04:00
|
|
|
[ CL_PLATFORM_EXTENSIONS platform-info-string ]
|
2010-03-03 03:02:47 -05:00
|
|
|
} cleave ;
|
|
|
|
|
|
|
|
: cl_device_fp_config>flags ( ulong -- sequence )
|
|
|
|
[ {
|
|
|
|
[ CL_FP_DENORM bitand 0 = [ f ] [ cl-denorm ] if ]
|
|
|
|
[ CL_FP_INF_NAN bitand 0 = [ f ] [ cl-inf-and-nan ] if ]
|
|
|
|
[ CL_FP_ROUND_TO_NEAREST bitand 0 = [ f ] [ cl-round-to-nearest ] if ]
|
|
|
|
[ CL_FP_ROUND_TO_ZERO bitand 0 = [ f ] [ cl-round-to-zero ] if ]
|
|
|
|
[ CL_FP_ROUND_TO_INF bitand 0 = [ f ] [ cl-round-to-inf ] if ]
|
|
|
|
[ CL_FP_FMA bitand 0 = [ f ] [ cl-fma ] if ]
|
|
|
|
} cleave ] { } output>sequence sift ;
|
|
|
|
|
|
|
|
: cl_device_mem_cache_type>cache-type ( uint -- cache-type )
|
|
|
|
{
|
|
|
|
{ CL_NONE [ cl-no-cache ] }
|
|
|
|
{ CL_READ_ONLY_CACHE [ cl-read-only-cache ] }
|
|
|
|
{ CL_READ_WRITE_CACHE [ cl-read-write-cache ] }
|
2010-03-03 05:06:58 -05:00
|
|
|
} case ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: device-info-bool ( handle name -- ? )
|
2010-04-14 04:28:21 -04:00
|
|
|
[ clGetDeviceInfo ] info-bool ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: device-info-ulong ( handle name -- ulong )
|
2010-04-14 04:28:21 -04:00
|
|
|
[ clGetDeviceInfo ] info-ulong ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: device-info-uint ( handle name -- uint )
|
2010-04-14 04:28:21 -04:00
|
|
|
[ clGetDeviceInfo ] info-uint ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: device-info-string ( handle name -- string )
|
2010-04-14 04:28:21 -04:00
|
|
|
[ clGetDeviceInfo ] info-string ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: device-info-size_t ( handle name -- size_t )
|
2010-04-14 04:28:21 -04:00
|
|
|
[ clGetDeviceInfo ] info-size_t ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: device-info-size_t-array ( handle name -- size_t-array )
|
2010-04-14 04:28:21 -04:00
|
|
|
[ clGetDeviceInfo ] info-size_t-array ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: device-info ( device-id -- device )
|
|
|
|
dup {
|
2010-03-03 05:06:58 -05:00
|
|
|
[ CL_DEVICE_TYPE device-info-size_t size_t>cl-device-type ]
|
2010-03-03 03:02:47 -05:00
|
|
|
[ CL_DEVICE_VENDOR_ID device-info-uint ]
|
|
|
|
[ CL_DEVICE_MAX_COMPUTE_UNITS device-info-uint ]
|
|
|
|
[ CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS device-info-uint ]
|
|
|
|
[ CL_DEVICE_MAX_WORK_ITEM_SIZES device-info-size_t-array ]
|
|
|
|
[ CL_DEVICE_MAX_WORK_GROUP_SIZE device-info-size_t ]
|
|
|
|
[ CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR device-info-uint ]
|
|
|
|
[ CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT device-info-uint ]
|
|
|
|
[ CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT device-info-uint ]
|
|
|
|
[ CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG device-info-uint ]
|
|
|
|
[ CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT device-info-uint ]
|
|
|
|
[ CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE device-info-uint ]
|
|
|
|
[ CL_DEVICE_MAX_CLOCK_FREQUENCY device-info-uint ]
|
|
|
|
[ CL_DEVICE_ADDRESS_BITS device-info-uint ]
|
|
|
|
[ CL_DEVICE_MAX_MEM_ALLOC_SIZE device-info-ulong ]
|
|
|
|
[ CL_DEVICE_IMAGE_SUPPORT device-info-bool ]
|
|
|
|
[ CL_DEVICE_MAX_READ_IMAGE_ARGS device-info-uint ]
|
|
|
|
[ CL_DEVICE_MAX_WRITE_IMAGE_ARGS device-info-uint ]
|
|
|
|
[ CL_DEVICE_IMAGE2D_MAX_WIDTH device-info-size_t ]
|
|
|
|
[ CL_DEVICE_IMAGE2D_MAX_HEIGHT device-info-size_t ]
|
|
|
|
[ CL_DEVICE_IMAGE3D_MAX_WIDTH device-info-size_t ]
|
|
|
|
[ CL_DEVICE_IMAGE3D_MAX_HEIGHT device-info-size_t ]
|
|
|
|
[ CL_DEVICE_IMAGE3D_MAX_DEPTH device-info-size_t ]
|
|
|
|
[ CL_DEVICE_MAX_SAMPLERS device-info-uint ]
|
|
|
|
[ CL_DEVICE_MAX_PARAMETER_SIZE device-info-size_t ]
|
|
|
|
[ CL_DEVICE_MEM_BASE_ADDR_ALIGN device-info-uint ]
|
|
|
|
[ CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE device-info-uint ]
|
|
|
|
[ CL_DEVICE_SINGLE_FP_CONFIG device-info-ulong cl_device_fp_config>flags ]
|
|
|
|
[ CL_DEVICE_GLOBAL_MEM_CACHE_TYPE device-info-uint cl_device_mem_cache_type>cache-type ]
|
|
|
|
[ CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE device-info-uint ]
|
|
|
|
[ CL_DEVICE_GLOBAL_MEM_CACHE_SIZE device-info-ulong ]
|
|
|
|
[ CL_DEVICE_GLOBAL_MEM_SIZE device-info-ulong ]
|
|
|
|
[ CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE device-info-ulong ]
|
|
|
|
[ CL_DEVICE_MAX_CONSTANT_ARGS device-info-uint ]
|
|
|
|
[ CL_DEVICE_LOCAL_MEM_TYPE device-info-uint CL_LOCAL = ]
|
|
|
|
[ CL_DEVICE_LOCAL_MEM_SIZE device-info-ulong ]
|
|
|
|
[ CL_DEVICE_ERROR_CORRECTION_SUPPORT device-info-bool ]
|
|
|
|
[ CL_DEVICE_PROFILING_TIMER_RESOLUTION device-info-size_t ]
|
|
|
|
[ CL_DEVICE_ENDIAN_LITTLE device-info-bool ]
|
|
|
|
[ CL_DEVICE_AVAILABLE device-info-bool ]
|
|
|
|
[ CL_DEVICE_COMPILER_AVAILABLE device-info-bool ]
|
|
|
|
[ CL_DEVICE_EXECUTION_CAPABILITIES device-info-ulong CL_EXEC_KERNEL bitand 0 = not ]
|
|
|
|
[ CL_DEVICE_EXECUTION_CAPABILITIES device-info-ulong CL_EXEC_NATIVE_KERNEL bitand 0 = not ]
|
|
|
|
[ CL_DEVICE_QUEUE_PROPERTIES device-info-ulong CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE bitand 0 = not ]
|
|
|
|
[ CL_DEVICE_QUEUE_PROPERTIES device-info-ulong CL_QUEUE_PROFILING_ENABLE bitand 0 = not ]
|
|
|
|
[ CL_DEVICE_NAME device-info-string ]
|
|
|
|
[ CL_DEVICE_VENDOR device-info-string ]
|
|
|
|
[ CL_DRIVER_VERSION device-info-string ]
|
|
|
|
[ CL_DEVICE_PROFILE device-info-string ]
|
|
|
|
[ CL_DEVICE_VERSION device-info-string ]
|
|
|
|
[ CL_DEVICE_EXTENSIONS device-info-string ]
|
|
|
|
} cleave cl-device boa ;
|
|
|
|
|
|
|
|
: platform-devices ( platform-id -- devices )
|
|
|
|
CL_DEVICE_TYPE_ALL [
|
2010-10-20 18:42:53 -04:00
|
|
|
0 f 0 uint <ref> [ clGetDeviceIDs cl-success ] keep uint deref
|
2010-03-03 03:02:47 -05:00
|
|
|
] [
|
2011-09-25 14:49:27 -04:00
|
|
|
rot dup void* <c-array> [ f clGetDeviceIDs cl-success ] keep
|
2010-03-03 05:06:58 -05:00
|
|
|
] 2bi ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: command-queue-info-ulong ( handle name -- ulong )
|
2010-04-14 04:28:21 -04:00
|
|
|
[ clGetCommandQueueInfo ] info-ulong ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: sampler-info-bool ( handle name -- ? )
|
2010-04-14 04:28:21 -04:00
|
|
|
[ clGetSamplerInfo ] info-bool ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: sampler-info-uint ( handle name -- uint )
|
2010-04-14 04:28:21 -04:00
|
|
|
[ clGetSamplerInfo ] info-uint ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: program-build-info-string ( program-handle device-handle name -- string )
|
2010-04-14 04:28:21 -04:00
|
|
|
[ clGetProgramBuildInfo ] 2info-string ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: program-build-log ( program-handle device-handle -- string )
|
2010-04-14 04:28:21 -04:00
|
|
|
CL_PROGRAM_BUILD_LOG program-build-info-string ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: strings>char*-array ( strings -- char*-array )
|
2015-07-14 23:45:13 -04:00
|
|
|
[
|
|
|
|
ascii encode dup length dup malloc
|
|
|
|
[ cl-not-null ] keep &free [ -rot memcpy ] keep
|
|
|
|
] void*-array{ } map-as ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: (program) ( cl-context sources -- program-handle )
|
|
|
|
[ handle>> ] dip [
|
|
|
|
[ length ]
|
|
|
|
[ strings>char*-array ]
|
|
|
|
[ [ length ] size_t-array{ } map-as ] tri
|
2010-10-20 18:42:53 -04:00
|
|
|
0 int <ref> [ clCreateProgramWithSource ] keep int deref cl-success
|
2010-03-03 03:02:47 -05:00
|
|
|
] with-destructors ;
|
|
|
|
|
|
|
|
:: (build-program) ( program-handle device options -- program )
|
|
|
|
program-handle 1 device 1array [ id>> ] void*-array{ } map-as
|
2010-03-03 05:06:58 -05:00
|
|
|
options ascii encode 0 suffix f f clBuildProgram
|
|
|
|
{
|
2010-03-03 03:02:47 -05:00
|
|
|
{ CL_BUILD_PROGRAM_FAILURE [
|
|
|
|
program-handle device id>> program-build-log program-handle
|
2015-08-13 19:13:05 -04:00
|
|
|
clReleaseProgram cl-success cl-error f ] }
|
2010-03-03 03:02:47 -05:00
|
|
|
{ CL_SUCCESS [ cl-program new-disposable program-handle >>handle ] }
|
|
|
|
[ program-handle clReleaseProgram cl-success cl-success f ]
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
: kernel-info-string ( handle name -- string )
|
2010-04-14 04:28:21 -04:00
|
|
|
[ clGetKernelInfo ] info-string ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: kernel-info-uint ( handle name -- uint )
|
2010-04-14 04:28:21 -04:00
|
|
|
[ clGetKernelInfo ] info-uint ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: kernel-work-group-info-size_t ( handle1 handle2 name -- size_t )
|
2010-04-14 04:28:21 -04:00
|
|
|
[ clGetKernelWorkGroupInfo ] 2info-size_t ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: event-info-uint ( handle name -- uint )
|
2010-04-14 04:28:21 -04:00
|
|
|
[ clGetEventInfo ] info-uint ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: event-info-int ( handle name -- int )
|
2010-04-14 04:28:21 -04:00
|
|
|
[ clGetEventInfo ] info-int ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: cl_command_type>command-type ( cl_command-type -- command-type )
|
|
|
|
{
|
|
|
|
{ CL_COMMAND_NDRANGE_KERNEL [ cl-ndrange-kernel-command ] }
|
|
|
|
{ CL_COMMAND_TASK [ cl-task-command ] }
|
|
|
|
{ CL_COMMAND_NATIVE_KERNEL [ cl-native-kernel-command ] }
|
|
|
|
{ CL_COMMAND_READ_BUFFER [ cl-read-buffer-command ] }
|
|
|
|
{ CL_COMMAND_WRITE_BUFFER [ cl-write-buffer-command ] }
|
|
|
|
{ CL_COMMAND_COPY_BUFFER [ cl-copy-buffer-command ] }
|
|
|
|
{ CL_COMMAND_READ_IMAGE [ cl-read-image-command ] }
|
|
|
|
{ CL_COMMAND_WRITE_IMAGE [ cl-write-image-command ] }
|
|
|
|
{ CL_COMMAND_COPY_IMAGE [ cl-copy-image-command ] }
|
|
|
|
{ CL_COMMAND_COPY_BUFFER_TO_IMAGE [ cl-copy-buffer-to-image-command ] }
|
|
|
|
{ CL_COMMAND_COPY_IMAGE_TO_BUFFER [ cl-copy-image-to-buffer-command ] }
|
|
|
|
{ CL_COMMAND_MAP_BUFFER [ cl-map-buffer-command ] }
|
|
|
|
{ CL_COMMAND_MAP_IMAGE [ cl-map-image-command ] }
|
|
|
|
{ CL_COMMAND_UNMAP_MEM_OBJECT [ cl-unmap-mem-object-command ] }
|
|
|
|
{ CL_COMMAND_MARKER [ cl-marker-command ] }
|
|
|
|
{ CL_COMMAND_ACQUIRE_GL_OBJECTS [ cl-acquire-gl-objects-command ] }
|
|
|
|
{ CL_COMMAND_RELEASE_GL_OBJECTS [ cl-release-gl-objects-command ] }
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
: cl_int>execution-status ( clint -- execution-status )
|
|
|
|
{
|
|
|
|
{ CL_QUEUED [ cl-queued ] }
|
|
|
|
{ CL_SUBMITTED [ cl-submitted ] }
|
|
|
|
{ CL_RUNNING [ cl-running ] }
|
|
|
|
{ CL_COMPLETE [ cl-complete ] }
|
|
|
|
[ drop cl-failure ]
|
2010-03-03 05:06:58 -05:00
|
|
|
} case ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: profiling-info-ulong ( handle name -- ulong )
|
2010-04-14 04:28:21 -04:00
|
|
|
[ clGetEventProfilingInfo ] info-ulong ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: bind-kernel-arg-buffer ( kernel index buffer -- )
|
2010-10-25 14:22:50 -04:00
|
|
|
[ handle>> ] [ cl_mem heap-size ] [ handle>> void* deref ] tri*
|
2010-03-03 05:06:58 -05:00
|
|
|
clSetKernelArg cl-success ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: bind-kernel-arg-data ( kernel index byte-array -- )
|
|
|
|
[ handle>> ] 2dip
|
2010-03-03 05:06:58 -05:00
|
|
|
[ byte-length ] keep clSetKernelArg cl-success ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
GENERIC: bind-kernel-arg ( kernel index data -- )
|
|
|
|
M: cl-buffer bind-kernel-arg bind-kernel-arg-buffer ;
|
|
|
|
M: byte-array bind-kernel-arg bind-kernel-arg-data ;
|
2012-07-19 14:24:45 -04:00
|
|
|
|
2010-03-03 03:02:47 -05:00
|
|
|
PRIVATE>
|
|
|
|
|
|
|
|
: with-cl-state ( context/f device/f queue/f quot -- )
|
|
|
|
[
|
|
|
|
[
|
2012-07-19 14:24:45 -04:00
|
|
|
[ cl-current-queue ,, ] when*
|
|
|
|
[ cl-current-device ,, ] when*
|
|
|
|
[ cl-current-context ,, ] when*
|
|
|
|
] 3curry H{ } make
|
2012-10-22 17:02:19 -04:00
|
|
|
] dip with-variables ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: cl-platforms ( -- platforms )
|
2010-10-20 18:42:53 -04:00
|
|
|
0 f 0 uint <ref> [ clGetPlatformIDs cl-success ] keep uint deref
|
2011-09-25 14:49:27 -04:00
|
|
|
dup void* <c-array> [ f clGetPlatformIDs cl-success ] keep
|
2010-03-03 03:02:47 -05:00
|
|
|
[
|
|
|
|
dup
|
|
|
|
[ platform-info ]
|
|
|
|
[ platform-devices [ device-info ] { } map-as ] bi
|
|
|
|
cl-platform boa
|
|
|
|
] { } map-as ;
|
|
|
|
|
|
|
|
: <cl-context> ( devices -- cl-context )
|
|
|
|
[ f ] dip
|
|
|
|
[ length ] [ [ id>> ] void*-array{ } map-as ] bi
|
2010-10-20 18:42:53 -04:00
|
|
|
f f 0 int <ref> [ clCreateContext ] keep int deref cl-success
|
2010-03-03 03:02:47 -05:00
|
|
|
cl-context new-disposable swap >>handle ;
|
|
|
|
|
|
|
|
: <cl-queue> ( context device out-of-order? profiling? -- command-queue )
|
|
|
|
[ [ handle>> ] [ id>> ] bi* ] 2dip
|
|
|
|
[ [ CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE ] [ 0 ] if ]
|
|
|
|
[ [ CL_QUEUE_PROFILING_ENABLE ] [ 0 ] if ] bi* bitor
|
2010-10-20 18:42:53 -04:00
|
|
|
0 int <ref> [ clCreateCommandQueue ] keep int deref cl-success
|
2010-03-03 03:02:47 -05:00
|
|
|
cl-queue new-disposable swap >>handle ;
|
|
|
|
|
|
|
|
: cl-out-of-order-execution? ( command-queue -- ? )
|
|
|
|
CL_QUEUE_PROPERTIES command-queue-info-ulong
|
2010-03-03 05:06:58 -05:00
|
|
|
CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE bitand 0 = not ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: cl-profiling? ( command-queue -- ? )
|
|
|
|
CL_QUEUE_PROPERTIES command-queue-info-ulong
|
2010-03-03 05:06:58 -05:00
|
|
|
CL_QUEUE_PROFILING_ENABLE bitand 0 = not ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: <cl-buffer> ( buffer-access-mode size initial-data -- buffer )
|
|
|
|
[ (current-cl-context) ] 3dip
|
2018-06-19 20:15:05 -04:00
|
|
|
tuck [
|
2010-03-03 03:02:47 -05:00
|
|
|
[ handle>> ]
|
|
|
|
[ buffer-access-constant ]
|
|
|
|
[ [ CL_MEM_COPY_HOST_PTR ] [ CL_MEM_ALLOC_HOST_PTR ] if ] tri* bitor
|
|
|
|
] 2dip
|
2010-10-20 18:42:53 -04:00
|
|
|
0 int <ref> [ clCreateBuffer ] keep int deref cl-success
|
2010-03-03 03:02:47 -05:00
|
|
|
cl-buffer new-disposable swap >>handle ;
|
|
|
|
|
|
|
|
: cl-read-buffer ( buffer-range -- byte-array )
|
|
|
|
[ (current-cl-queue) handle>> ] dip
|
|
|
|
[ buffer>> handle>> CL_TRUE ]
|
|
|
|
[ offset>> ]
|
|
|
|
[ size>> dup <byte-array> ] tri
|
|
|
|
[ 0 f f clEnqueueReadBuffer cl-success ] keep ; inline
|
|
|
|
|
|
|
|
: cl-write-buffer ( buffer-range byte-array -- )
|
|
|
|
[
|
|
|
|
[ (current-cl-queue) handle>> ] dip
|
|
|
|
[ buffer>> handle>> CL_TRUE ]
|
|
|
|
[ offset>> ]
|
|
|
|
[ size>> ] tri
|
|
|
|
] dip 0 f f clEnqueueWriteBuffer cl-success ; inline
|
|
|
|
|
|
|
|
: cl-queue-copy-buffer ( src-buffer-ptr dst-buffer-ptr size dependent-events -- event )
|
|
|
|
[
|
|
|
|
(current-cl-queue)
|
|
|
|
[ handle>> ]
|
|
|
|
[ [ buffer>> handle>> ] [ offset>> ] bi ]
|
|
|
|
[ [ buffer>> handle>> ] [ offset>> ] bi ]
|
|
|
|
tri* swapd
|
|
|
|
] 2dip [ length ] keep [ f ] [ [ handle>> ] void*-array{ } map-as ] if-empty
|
2010-10-25 14:22:50 -04:00
|
|
|
f void* <ref> [ clEnqueueCopyBuffer cl-success ] keep void* deref cl-event
|
2010-03-03 03:02:47 -05:00
|
|
|
new-disposable swap >>handle ;
|
|
|
|
|
|
|
|
: cl-queue-read-buffer ( buffer-range alien dependent-events -- event )
|
|
|
|
[
|
|
|
|
[ (current-cl-queue) handle>> ] dip
|
|
|
|
[ buffer>> handle>> CL_FALSE ] [ offset>> ] [ size>> ] tri
|
|
|
|
] 2dip [ length ] keep [ f ] [ [ handle>> ] void*-array{ } map-as ] if-empty
|
2015-07-14 23:45:13 -04:00
|
|
|
f void* <ref> [ clEnqueueReadBuffer cl-success ] keep void* deref cl-event
|
2010-03-03 03:02:47 -05:00
|
|
|
new-disposable swap >>handle ;
|
|
|
|
|
|
|
|
: cl-queue-write-buffer ( buffer-range alien dependent-events -- event )
|
|
|
|
[
|
|
|
|
[ (current-cl-queue) handle>> ] dip
|
|
|
|
[ buffer>> handle>> CL_FALSE ] [ offset>> ] [ size>> ] tri
|
|
|
|
] 2dip [ length ] keep [ f ] [ [ handle>> ] void*-array{ } map-as ] if-empty
|
2010-10-25 14:22:50 -04:00
|
|
|
f void* <ref> [ clEnqueueWriteBuffer cl-success ] keep void* deref cl-event
|
2010-03-03 03:02:47 -05:00
|
|
|
new-disposable swap >>handle ;
|
|
|
|
|
|
|
|
: <cl-sampler> ( normalized-coords? addressing-mode filter-mode -- sampler )
|
|
|
|
[ (current-cl-context) ] 3dip
|
|
|
|
[ [ CL_TRUE ] [ CL_FALSE ] if ]
|
|
|
|
[ addressing-mode-constant ]
|
|
|
|
[ filter-mode-constant ]
|
2015-06-29 19:43:15 -04:00
|
|
|
tri* 0 int <ref> [ clCreateSampler ] keep int deref cl-success
|
2010-03-03 03:02:47 -05:00
|
|
|
cl-sampler new-disposable swap >>handle ;
|
|
|
|
|
|
|
|
: cl-normalized-coords? ( sampler -- ? )
|
2010-03-03 05:06:58 -05:00
|
|
|
handle>> CL_SAMPLER_NORMALIZED_COORDS sampler-info-bool ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
2013-03-24 13:03:49 -04:00
|
|
|
: sampler>cl-addressing-mode ( sampler -- addressing-mode )
|
2010-03-03 05:06:58 -05:00
|
|
|
handle>> CL_SAMPLER_ADDRESSING_MODE sampler-info-uint cl_addressing_mode>addressing-mode ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
2013-03-24 13:03:49 -04:00
|
|
|
: sampler>cl-filter-mode ( sampler -- filter-mode )
|
2010-03-03 05:06:58 -05:00
|
|
|
handle>> CL_SAMPLER_FILTER_MODE sampler-info-uint cl_filter_mode>filter-mode ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: <cl-program> ( options strings -- program )
|
|
|
|
[ (current-cl-device) ] 2dip
|
|
|
|
[ (current-cl-context) ] dip
|
|
|
|
(program) -rot (build-program) ;
|
|
|
|
|
|
|
|
: <cl-kernel> ( program kernel-name -- kernel )
|
|
|
|
[ handle>> ] [ ascii encode 0 suffix ] bi*
|
2010-10-20 18:42:53 -04:00
|
|
|
0 int <ref> [ clCreateKernel ] keep int deref cl-success
|
2010-03-03 05:06:58 -05:00
|
|
|
cl-kernel new-disposable swap >>handle ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: cl-kernel-name ( kernel -- string )
|
2010-04-14 04:28:21 -04:00
|
|
|
handle>> CL_KERNEL_FUNCTION_NAME kernel-info-string ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: cl-kernel-arity ( kernel -- arity )
|
2010-04-14 04:28:21 -04:00
|
|
|
handle>> CL_KERNEL_NUM_ARGS kernel-info-uint ;
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: cl-kernel-local-size ( kernel -- size )
|
2010-03-03 05:06:58 -05:00
|
|
|
(current-cl-device) [ handle>> ] bi@ CL_KERNEL_WORK_GROUP_SIZE kernel-work-group-info-size_t ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
:: cl-queue-kernel ( kernel args sizes dependent-events -- event )
|
|
|
|
args [| arg idx | kernel idx arg bind-kernel-arg ] each-index
|
|
|
|
(current-cl-queue) handle>>
|
|
|
|
kernel handle>>
|
|
|
|
sizes [ length f ] [ [ ] size_t-array{ } map-as f ] bi
|
|
|
|
dependent-events [ length ] [ [ f ] [ [ handle>> ] void*-array{ } map-as ] if-empty ] bi
|
2010-10-25 14:22:50 -04:00
|
|
|
f void* <ref> [ clEnqueueNDRangeKernel cl-success ] keep void* deref
|
2010-03-03 03:02:47 -05:00
|
|
|
cl-event new-disposable swap >>handle ;
|
|
|
|
|
|
|
|
: cl-event-type ( event -- command-type )
|
2010-03-03 05:06:58 -05:00
|
|
|
handle>> CL_EVENT_COMMAND_TYPE event-info-uint cl_command_type>command-type ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: cl-event-status ( event -- execution-status )
|
2010-03-03 05:06:58 -05:00
|
|
|
handle>> CL_EVENT_COMMAND_EXECUTION_STATUS event-info-int cl_int>execution-status ; inline
|
2010-03-03 03:02:47 -05:00
|
|
|
|
|
|
|
: cl-profile-counters ( event -- queued submitted started finished )
|
|
|
|
handle>> {
|
|
|
|
[ CL_PROFILING_COMMAND_QUEUED profiling-info-ulong ]
|
|
|
|
[ CL_PROFILING_COMMAND_SUBMIT profiling-info-ulong ]
|
|
|
|
[ CL_PROFILING_COMMAND_START profiling-info-ulong ]
|
|
|
|
[ CL_PROFILING_COMMAND_END profiling-info-ulong ]
|
|
|
|
} cleave ; inline
|
|
|
|
|
|
|
|
: cl-barrier-events ( event/events -- )
|
|
|
|
[ (current-cl-queue) handle>> ] dip
|
|
|
|
dup sequence? [ 1array ] unless
|
|
|
|
[ handle>> ] void*-array{ } map-as [ length ] keep clEnqueueWaitForEvents cl-success ; inline
|
|
|
|
|
|
|
|
: cl-marker ( -- event )
|
|
|
|
(current-cl-queue)
|
2010-10-25 14:22:50 -04:00
|
|
|
f void* <ref> [ clEnqueueMarker cl-success ] keep void* deref cl-event new-disposable
|
2010-03-03 03:02:47 -05:00
|
|
|
swap >>handle ; inline
|
|
|
|
|
|
|
|
: cl-barrier ( -- )
|
|
|
|
(current-cl-queue) clEnqueueBarrier cl-success ; inline
|
2015-06-29 19:43:15 -04:00
|
|
|
|
2010-03-03 03:02:47 -05:00
|
|
|
: cl-flush ( -- )
|
|
|
|
(current-cl-queue) handle>> clFlush cl-success ; inline
|
|
|
|
|
|
|
|
: cl-wait ( event/events -- )
|
|
|
|
dup sequence? [ 1array ] unless
|
|
|
|
[ handle>> ] void*-array{ } map-as [ length ] keep clWaitForEvents cl-success ; inline
|
|
|
|
|
|
|
|
: cl-finish ( -- )
|
|
|
|
(current-cl-queue) handle>> clFinish cl-success ; inline
|