class dlstreamer::Context#

Overview#

This class represents context created on one of memory types listed in enum MemoryType. Context contains one or multiple handles associated with underlying framework or memory type, for example handle with type cl_context and key “cl_context” if OpenCL memory type. Context is capable to create memory mapping object for mapping to or from system memory, and potentially other memory types if supported by underlying framework. Context is capable to create another context on same device, if supported by underlying framework. More…

#include <context.h>

class Context {
public:
    // typedefs

    typedef void* handle_t;

    // methods

    virtual MemoryType memory_type() const = 0;
    virtual handle_t handle(std::string_view key = {}) const = 0;

    virtual MemoryMapperPtr get_mapper(
        const ContextPtr& input_context,
        const ContextPtr& output_context
    ) = 0;

    virtual ContextPtr derive_context(MemoryType memory_type) = 0;
    virtual ContextPtr parent() = 0;
};

// direct descendants

class BaseContext;

Detailed Documentation#

This class represents context created on one of memory types listed in enum MemoryType. Context contains one or multiple handles associated with underlying framework or memory type, for example handle with type cl_context and key “cl_context” if OpenCL memory type. Context is capable to create memory mapping object for mapping to or from system memory, and potentially other memory types if supported by underlying framework. Context is capable to create another context on same device, if supported by underlying framework.

Typedefs#

typedef void* handle_t

Type of handles stored in context.

Methods#

virtual MemoryType memory_type() const = 0

Returns memory type of this context.

virtual handle_t handle(std::string_view key = {}) const = 0

Returns a handle by key. If empty key, returns default handle. If no handle with the specified key, returns 0.

Parameters:

key

the key of the handle to find

virtual MemoryMapperPtr get_mapper(
    const ContextPtr& input_context,
    const ContextPtr& output_context
) = 0

Returns an object for memory mapping between two contexts. Function typically expects one of contexts to be this context. If one of contexts has memory type CPU or context reference is nullptr, function returns object for mapping to or from system memory. If creating memory mapping object failed, exception is thrown.

Parameters:

input_context

Context of input memory

output_context

Context of output memory

virtual ContextPtr derive_context(MemoryType memory_type) = 0

Create another context of specified memory type. New context belongs to same device (if multiple GPUs) as original context, and parent() returns reference to original context. If creating new context failed, function returns nullptr.

Parameters:

memory_type

Memory type of new context

virtual ContextPtr parent() = 0

Returns parent context if this context was created from another context via derive_context(), nullptr otherwise.