cuda-api-wrappers
Thin C++-flavored wrappers for the CUDA Runtime API
module.hpp File Reference

Wrappers for working with modules of compiled CUDA code. More...

#include "context.hpp"
#include "primary_context.hpp"
#include "kernel.hpp"
#include "memory.hpp"
#include "array.hpp"
#include "link_options.hpp"
#include <array>
Include dependency graph for module.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  cuda::module_t
 Wrapper class for a CUDA code module. More...
 

Namespaces

 cuda
 Definitions and functionality wrapping CUDA APIs.
 

Typedefs

using cuda::module::handle_t = CUmodule
 Raw CUDA driver handle of a module of compiled code; see module_t.
 

Functions

module_t cuda::module::load_from_file (const context_t &context, const char *path)
 Load a module from an appropriate compiled or semi-compiled file, allocating all relevant resources for it. More...
 
module_t cuda::module::load_from_file (const context_t &context, const ::std::string &path)
 
module_t cuda::module::load_from_file (const device_t &device, const char *path)
 
module_t cuda::module::load_from_file (const device_t &device, const ::std::string &path)
 
module_t cuda::module::load_from_file (const char *path)
 
module_t cuda::module::load_from_file (const ::std::string &path)
 
template<typename Locus , typename ContiguousContainer , cuda::detail_::enable_if_t< cuda::detail_::is_kinda_like_contiguous_container< ContiguousContainer >::value, bool > = true>
module_t cuda::module::create (Locus &&locus, ContiguousContainer module_data, const link::options_t &link_options)
 Create a CUDA driver module from raw module image data. More...
 
template<typename Locus , typename ContiguousContainer , cuda::detail_::enable_if_t< cuda::detail_::is_kinda_like_contiguous_container< ContiguousContainer >::value, bool > = true>
module_t cuda::module::create (Locus &&locus, ContiguousContainer module_data)
 Create a new module - in a specified context or in a device's primary context, using raw module data in memory. More...
 

Detailed Description

Wrappers for working with modules of compiled CUDA code.

Function Documentation

◆ create() [1/2]

template<typename Locus , typename ContiguousContainer , cuda::detail_::enable_if_t< cuda::detail_::is_kinda_like_contiguous_container< ContiguousContainer >::value, bool > = true>
module_t cuda::module::create ( Locus &&  locus,
ContiguousContainer  module_data,
const link::options_t link_options 
)

Create a CUDA driver module from raw module image data.

Parameters
[in]locuseither a context_t or a device_t - an entity for which one can obtain a CUDA context. This is the context into which the module data is to be loaded (and in which the module contents may be used)
[in]module_datathe opaque, raw binary data for the module - in a contiguous container such as a span, a cuda::unique_span etc..
link_optionsPotential options for the PTX compilation and linking of the compiled device-side code.
link_optionsOptions for PTX compilation and for linking the module data, eventually.
Returns

◆ create() [2/2]

template<typename Locus , typename ContiguousContainer , cuda::detail_::enable_if_t< cuda::detail_::is_kinda_like_contiguous_container< ContiguousContainer >::value, bool > = true>
module_t cuda::module::create ( Locus &&  locus,
ContiguousContainer  module_data 
)

Create a new module - in a specified context or in a device's primary context, using raw module data in memory.

Template Parameters
LocusEither a cuda::device_t or a {cuda::context_t}.
ContiguousContainerA span, a vector, a unique_span, or similar type
Parameters
locusWhere the new module should be created
module_dataThe raw data for the module in locus-accessible memory.
Note
This function may create/allocate resources for the primary context of a device!

◆ load_from_file() [1/6]

module_t cuda::module::load_from_file ( const context_t context,
const char *  path 
)
inline

Load a module from an appropriate compiled or semi-compiled file, allocating all relevant resources for it.

Parameters
pathof a cubin, PTX, or fatbin file constituting the module to be loaded.
contextThe context in which to create a module containing the loaded data
Returns
the loaded module
Note
this covers cuModuleLoadFatBinary() even though that's not directly used
Todo:

consider adding load_module methods to context_t

When switching to the C++17 standard, use string_view's instead of the const char* and ::std::string reference

◆ load_from_file() [2/6]

module_t cuda::module::load_from_file ( const context_t context,
const ::std::string &  path 
)
inline

◆ load_from_file() [3/6]

module_t cuda::module::load_from_file ( const device_t device,
const char *  path 
)
inline

Parameters
deviceThe device in whose primary context to create a module containing the loaded data

◆ load_from_file() [4/6]

module_t cuda::module::load_from_file ( const device_t device,
const ::std::string &  path 
)
inline

Parameters
deviceThe device in whose primary context to create a module containing the loaded data

◆ load_from_file() [5/6]

module_t cuda::module::load_from_file ( const char *  path)
inline

Note
loads the module into the primary context of the device of the current context (although not necessarily in the current context!)

◆ load_from_file() [6/6]

module_t cuda::module::load_from_file ( const ::std::string &  path)
inline