Class Kernel

Nested Relationships

Class Documentation

class legion::core::compute::Kernel

Wraps a cl_kernel, allows you to parametrize an OpenCL kernel without worrying about the CommandQueue.

Public Types

using dimension = std::variant<size_type, d2, d3>

Public Functions

Kernel(Program*, cl_kernel)
inline Kernel(const Kernel &other)
inline Kernel(Kernel &&other) noexcept
inline Kernel &operator=(const Kernel &other)
inline Kernel &operator=(Kernel &&other) noexcept
inline ~Kernel()
Kernel &local(size_type)

Determines the “Local Work Size”, aka how many Kernels should run in parallel This number should not exceed the amount of available cores, a good max is 1024.

Kernel &global(dimension)

Determines the “Global Work Size”, aka how many Kernels should run in total This number should match your input arrays (but not exceed it!)

Kernel &global(size_type, size_type)
Kernel &global(size_type, size_type, size_type)
Kernel &buildBufferNames()

Maps Parameter Names to indices, for example:

__kernel void do_something(__global int* Parameter1, __global int* Parameter2) { ... }
would be mapped to:
  • Parameter1 -> 0

  • Parameter2 -> 1

Kernel &readWriteMode(buffer_type)

Sets the modus operandi for Read-Write Buffers:

  • if you set read_write_mode to READ_BUFFER the next Read-Write Buffer will be read

  • if you set read_write_mode to WRITE_BUFFER the next Read-Writer Buffer will be written

  • setting it to READ | WRITE does not work and will throw a logic_error exception when trying to enqueue

Kernel &enqueueBuffer(Buffer buffer, block_mode blocking = block_mode::BLOCKING)

Enqueues a Buffer in the command queue, write buffers need to be enqueued before dispatching the kernel, read buffers afterwards.

Parameters
  • buffer: The buffer you want to enqueue.

  • index: The index of the Buffer you want to enqueue to (this must match the kernel index)

  • blocking: Whether or not you want a blocking write/read (default=BLOCKING)

Kernel &setBuffer(Buffer buffer)

Sets a Buffer as the Kernel Argument.

Note

this is required for all Kernel Arguments regardless of buffer direction

Note

this needs to be done for all buffers before the kernel is dispatched

Note

This Overload requires that the buffer is named

Parameters
  • buffer: The buffer you want to inform the kernel about

Kernel &setBuffer(Buffer buffer, const std::string &name)

Sets a Buffer as the Kernel Argument.

Note

this is required for all Kernel Arguments regardless of buffer direction

Note

this needs to be done for all buffers before the kernel is dispatched

Parameters
  • buffer: The buffer you want to inform the kernel about

  • name: The name of the Buffer you want to inform the kernel about

Kernel &setBuffer(Buffer buffer, cl_uint index)

Sets a Buffer as the Kernel Argument.

Note

this is required for all Kernel Arguments regardless of buffer direction

Note

this needs to be done for all buffers before the kernel is dispatched

Parameters
  • buffer: The buffer you want to inform the kernel about

  • index: The index of the Buffer you want to inform the kernel about

template<class T>
inline Kernel &setKernelArg(T *value, const std::string &name)

Sets a Kernel Parameter that is the same for all invocations of the kernel.

Template Parameters
  • T: The type of the Kernel Argument.

Parameters
  • value: A pointer to the value of the kernel Argument.

  • name: The name of the Kernel Argument as it appears in the Kernel.

template<class T>
inline Kernel &setKernelArg(T *value, cl_uint index)

Sets a Kernel Parameter that is the same for all invocations of the kernel.

Template Parameters
  • T: The type of the Kernel Argument.

Parameters
  • value: A pointer to the value of the kernel Argument.

  • index: The index of the parameter.

Kernel &setKernelArg(void *value, size_type size, const std::string &name)

See above.

Parameters
  • value: Value of the parameter.

  • size: Sizeof of the parameter.

  • name: The name of the Kernel Argument as it appears in the Kernel.

Kernel &setKernelArg(void *value, size_type size, cl_uint index)

See above.

Parameters
  • value: Value of the parameter.

  • size: Sizeof of the parameter.

  • index: The index of the parameter.

Kernel &setAndEnqueueBuffer(Buffer buffer, block_mode blocking = block_mode::BLOCKING)

same as informing the kernel about a buffer and then enqueueing it

Kernel &setAndEnqueueBuffer(Buffer buffer, const std::string&, block_mode blocking = block_mode::BLOCKING)

same as informing the kernel about a buffer and then enqueueing it

Kernel &setAndEnqueueBuffer(Buffer buffer, cl_uint index, block_mode blocking = block_mode::BLOCKING)

same as informing the kernel about a buffer and then enqueueing it

Kernel &dispatch()

Dispatches the Kernel to the command-queue.

Note

All Kernel Parameters must be set before this can be called

Note

global and local must be set before this can be called

Pre

set_buffer

Pre

set_and_enqueue_buffer

Pre

local

Pre

global

void finish() const

Ensures that the command-queue is committed and finished executing.

Pre

dispatch

size_type getMaxWorkSize() const

Gets the maximum parallel work size for this kernel.

struct d2

Public Members

size_type s0
size_type s1
struct d3

Public Members

size_type s0
size_type s1
size_type s3