Execution & Memory Spaces
Kokkos.Space
— TypeSpace
Abstract super type of all execution and memory spaces.
Main subtypes:
ExecutionSpaces
: super type of all execution spacesMemorySpaces
: super type of all memory spaces
All Kokkos spaces have a main abstract type (Serial
, Cuda
, HostSpace
, HIPSpace
...) which are defined even if it has not been compiled on the C++ side. Those main abstract types should be the ones used when specifying a space. This allows methods like enabled
to work independently from the wrapper library.
When a space is enabled, a sub-type of its main type is defined by CxxWrap
, leading to the following type structure: SerialImplAllocated <: SerialImpl <: Serial <: ExecutionSpace <: Space
. Below the main space type (here, Serial
), the sub-types are only defined if they are enabled, and therefore they should not be relied upon.
Navigating the type tree can be made easier through main_space_type
.
Kokkos.ExecutionSpace
— TypeExecutionSpace <: Space
Abstract super-type of all execution spaces.
Sub-types:
Serial
OpenMP
OpenACC
OpenMPTarget
Threads
Cuda
HIP
HPX
SYCL
All sub-types are always defined, but only some of them are enabled
. To enable an execution space, you must enable its related Kokkos backend, e.g. "-DKokkos_ENABLE_SERIAL=ON"
for the Serial
execution space.
To do this you can set the backends option with Kokkos.set_backends
, or specify the option directly through kokkos_options.
Kokkos.MemorySpace
— TypeMemorySpace <: Space
Abstract super-type of all memory spaces.
Sub-types:
HostSpace
CudaSpace
CudaHostPinnedSpace
CudaUVMSpace
HIPSpace
HIPHostPinnedSpace
HIPManagedSpace
Sub-types work the same as for ExecutionSpace
. They can be enabled by enabling their respective backend.
Kokkos.accessible
— Methodaccessible([S1::Union{<:Space, Type{<:Space}},] S2::Union{<:MemorySpace, Type{<:MemorySpace}})
Return true
if the memory space S2
is accessible from S1
(a memory or execution space).
If only S2
is specified, S1
defaults to DEFAULT_HOST_SPACE
.
Equivalent to Kokkos::SpaceAccessibility<S1, S2>::accessible
Kokkos.array_layout
— Methodarray_layout(exec_space::Union{<:ExecutionSpace, Type{<:ExecutionSpace}})
Return the default array layout type of the given execution space.
Kokkos.enabled
— Functionenabled(space::Union{Space, Type{<:Space}})
Return true if the given execution or memory space is enabled.
Kokkos.execution_space
— Functionexecution_space(space::Union{<:MemorySpace, Type{<:MemorySpace}})
Return the execution space associated by default to the given memory space.
Kokkos.memory_space
— Methodmemory_space(space::Union{<:ExecutionSpace, Type{<:ExecutionSpace}})
Return the memory space associated by default to the given execution space.
Kokkos.main_space_type
— Functionmain_space_type(space::Union{<:Space, Type{<:Space}})
Return the main space type of space
, e.g. for Serial
, SerialImpl
or SerialImplAllocated
we get Serial
.
Kokkos.impl_space_type
— Functionimpl_space_type(::Type{<:Space})
Opposite of main_space_type
: from the main space type (Serial
, OpenMP
, HostSpace
...) return the implementation type (SerialImpl
, OpenMPImpl
, HostSpaceImpl
...). The given space must be enabled.
Kokkos.kokkos_name
— Functionkokkos_name(space::Union{Space, Type{<:Space}})
Return the name of the execution or memory space as defined by Kokkos.
Equivalent to Kokkos::space::name()
Kokkos.fence
— Methodfence(exec_space::ExecutionSpace)
Wait for all asynchronous tasks operating on this execution space instance to complete.
Equivalent to exec_space.fence()
.
Kokkos.concurrency
— Functionconcurrency(exec_space::ExecutionSpace)
The maximum number of threads utilized by the execution space instance.
Equivalent to exec_space.concurrency()
.
Kokkos.allocate
— Functionallocate(mem_space::MemorySpace, bytes)
Allocate bytes
on the memory space instance. Returns a pointer to the allocated memory.
Equivalent to mem_space.allocate(bytes)
Kokkos.deallocate
— Functiondeallocate(mem_space::MemorySpace, ptr)
Frees ptr
, previously allocated with allocate
.
Equivalent to mem_space.deallocate(ptr, bytes)
Constants
Kokkos.ENABLED_EXEC_SPACES
— ConstantENABLED_EXEC_SPACES::Tuple{Vararg{Type{<:ExecutionSpace}}}
List of all enabled Kokkos execution spaces.
nothing
if Kokkos is not yet loaded.
Kokkos.ENABLED_MEM_SPACES
— ConstantENABLED_MEM_SPACES::Tuple{Vararg{Type{<:MemorySpace}}}
List of all enabled Kokkos memory spaces.
nothing
if Kokkos is not yet loaded.
Default spaces
Kokkos.DEFAULT_DEVICE_SPACE
— ConstantDEFAULT_DEVICE_SPACE::Type{<:ExecutionSpace}
The default execution space where kernels are applied on the device.
Equivalent to Kokkos::DefaultExecutionSpace
.
nothing
if Kokkos is not yet loaded.
Kokkos.DEFAULT_DEVICE_MEM_SPACE
— ConstantDEFAULT_DEVICE_MEM_SPACE::Type{<:MemorySpace}
The default memory space where views are stored on the device.
Equivalent to Kokkos::DefaultExecutionSpace::memory_space
.
nothing
if Kokkos is not yet loaded.
Kokkos.DEFAULT_HOST_SPACE
— ConstantDEFAULT_HOST_SPACE::Type{<:ExecutionSpace}
The default execution space where kernels are applied on the host.
Equivalent to Kokkos::DefaultHostExecutionSpace
.
nothing
if Kokkos is not yet loaded.
Kokkos.DEFAULT_HOST_MEM_SPACE
— ConstantDEFAULT_HOST_MEM_SPACE::Type{<:MemorySpace}
The default memory space where views are stored on the host.
Equivalent to Kokkos::DefaultHostExecutionSpace::memory_space
.
nothing
if Kokkos is not yet loaded.
Kokkos.SHARED_MEMORY_SPACE
— ConstantSHARED_MEMORY_SPACE::Union{Nothing, Type{<:MemorySpace}}
The shared memory space between the host and device, or nothing
if there is none.
Equivalent to Kokkos::SharedSpace
if Kokkos::has_shared_space
is true
.
nothing
if Kokkos is not yet loaded.
Kokkos.SHARED_HOST_PINNED_MEMORY_SPACE
— ConstantSHARED_HOST_PINNED_MEMORY_SPACE::Union{Nothing, Type{<:MemorySpace}}
The shared pinned memory space between the host and device, or nothing
if there is none.
Equivalent to Kokkos::SharedHostPinnedSpace
if Kokkos::has_shared_host_pinned_space
is true
.
nothing
if Kokkos is not yet loaded.
Backend-specific methods
Those unexported methods are defined in the Kokkos.BackendFunctions
module. They have methods only if their respective backend is enabled and Kokkos is initialized.
OpenMP
Some functions of the OpenMP runtime are made available through Kokkos.jl
, mostly for debugging purposes and tracking thread affinity.
Kokkos.BackendFunctions.omp_set_num_threads
— Functionomp_set_num_threads(threads::Cint)::Cvoid
Kokkos.BackendFunctions.omp_get_max_threads
— Functionomp_get_max_threads()::Cint
Kokkos.BackendFunctions.omp_get_proc_bind
— Functionomp_get_proc_bind()::Cint
Kokkos.BackendFunctions.omp_get_num_places
— Functionomp_get_num_places()::Cint
Kokkos.BackendFunctions.omp_get_place_num_procs
— Functionomp_get_place_num_procs(place::Cint)::Cint
Kokkos.BackendFunctions.omp_get_place_proc_ids
— Functionomp_get_place_proc_ids(place::Cint)::Vector{Cint}
Kokkos.BackendFunctions.omp_capture_affinity
— Functionomp_capture_affinity([format::String])::String
More or less equivalent to omp_display_affinity(char*)
, but applies the given format
(or OpenMP's default one) to each OpenMP thread using omp_capture_affinity
, and returns the result.
Cuda / HIP
Kokkos.device_id
— Functiondevice_id([space::Kokkos.Cuda])
device_id([space::Kokkos.HIP])
Return the ID of the device associated with the given space
. If space
is not given, the ID of the default device used by Kokkos is returned.
The ID is a 0-index in the list of available devices (as used by cudaGetDeviceProperties
or hipGetDeviceProperties
for example).
Equivalent to Kokkos::Cuda().cuda_device()
or Kokkos::HIP().hip_device()
.
Kokkos.BackendFunctions.wrap_stream
— Functionwrap_stream(cuda_stream::Ptr{Cvoid})::Kokkos.Cuda
wrap_stream(hip_stream::Ptr{Cvoid})::Kokkos.HIP
Return a Kokkos.Cuda
or Kokkos.HIP
execution space operating on the given stream (a pointer to a cudaStream_t
or hipStream_t
respectively). Kokkos does not take ownership of the stream.
Equivalent to Kokkos::Cuda(cuda_stream)
or Kokkos::HIP(hip_stream)
.
Kokkos.BackendFunctions.stream_ptr
— Functionstream_ptr(space::Kokkos.Cuda)
stream_ptr(space::Kokkos.HIP)
Return the cudaStream_t
or hipStream_t
of the space
as a Ptr{Cvoid}
.
Equivalent to Kokkos::Cuda().cuda_stream()
or Kokkos::HIP().hip_stream()
.
Kokkos.BackendFunctions.memory_info
— Functionmemory_info()
Return (free_memory, total_memory)
, in bytes, for the current active device.
Equivalent to cuMemGetInfo_v2
or hipMemGetInfo
.