-
Notifications
You must be signed in to change notification settings - Fork 0
Kokkos::MemorySpaceConcept
The concept of a MemorySpace
is the fundamental abstraction to represent the "where" and the "how" that memory allocation and access takes place in Kokkos. Most code that uses Kokkos should be written to the generic concept of a MemorySpace
rather than any specific instance. This page talks practically about how to use the common features of memory spaces in Kokkos; for a more formal and theoretical treatment, see this document.
Disclaimer: There is nothing new about the term "concept" in C++; anyone who has ever used templates in C++ has used concepts whether they knew it or not. Please do not be confused by the word "concept" itself, which is now more often associated with a shiny new C++20 language feature. Here, "concept" just means "what you're allowed to do with a type that is a template parameter in certain places".
// This is not an actual class, it just describes the concept in shorthand
class MemorySpaceConcept {
public:
typedef MemorySpaceConcept memory_space;
typedef ... execution_space;
typedef Device<execution_space, memory_space> device_type;
MemorySpaceConcept();
MemorySpaceConcept(const MemorySpaceConcept& src);
const char* name() const;
void * allocate(ptrdiff_t size) const;
void deallocate(void* ptr, ptrdiff_t size) const;
};
template<class MS>
struct is_memory_space {
enum { value = false };
};
template<>
struct is_memory_space<MemorySpaceConcept> {
enum { value = true };
};
-
memory_space
: The self type; -
execution_space
: the defaultExecutionSpace
to use when constructing objects in memory provided by an instance ofMemorySpace
, or (potentially) when deep copying from or to such memory (seedeep_copy
documentation for details). Kokkos guarantees thatKokkos::SpaceAccessibility<execution_space, memory_space>::accessible
will betrue
(seeKokkos::SpaceAccessibility
). -
device_type
:DeviceType<execution_space,memory_space>
.
-
MemorySpaceConcept()
: Default constructor. -
MemorySpaceConcept(const MemorySpaceConcept& src)
: Copy constructor.
-
const char* name() const;
: Returns the label of the memory space instance. -
void * allocate(ptrdiff_t size) const;
: Allocates a buffer of at leastsize
bytes using the memory resource thatMemorySpaceConcept
represents. -
void deallocate(void* ptr, ptrdiff_t size) const;
: Frees the buffer starting atptr
(of typevoid*
) previously allocated with exactlyallocate(size)
.
-
template<class MS> struct is_memory_space;
: typetrait to check whether a class is a memory space. -
template<class S1, class S2> struct SpaceAccessibility;
: typetraits to check whether two spaces are compatible (assignable, deep_copy-able, accessable).
Home:
- Introduction
- Machine Model
- Programming Model
- Compiling
- Initialization
- View
- Parallel Dispatch
- Hierarchical Parallelism
- Custom Reductions
- Atomic Operations
- Subviews
- Interoperability
- Kokkos and Virtual Functions
- Initialization and Finalization
- View
- Data Parallelism
- Execution Policies
- Spaces
- Task Parallelism
- Utilities
- STL Compatibility
- Numerics
- Detection Idiom