Loading...
Searching...
No Matches
gpr::linalg::EnvironmentGpuExecutor Class Reference

#include <gpr/linalg/EnvironmentGpuExecutor.h>

Classes

struct  Impl

Public Member Functions

 EnvironmentGpuExecutor (const std::string &library)
 ~EnvironmentGpuExecutor ()
 EnvironmentGpuExecutor (const EnvironmentGpuExecutor &)=delete
EnvironmentGpuExecutor & operator= (const EnvironmentGpuExecutor &)=delete
void assemble (const gpr::detail::EnvironmentPairBatch &batch, std::span< double > output) const

Detailed Description

Owns a device context; numerical inputs and outputs belong to each call. The implementation joins device work before returning to MPI callers.

Definition at line 17 of file EnvironmentGpuExecutor.h.

Constructor & Destructor Documentation

◆ EnvironmentGpuExecutor() [1/2]

gpr::linalg::EnvironmentGpuExecutor::EnvironmentGpuExecutor ( const std::string & library)
explicit

Definition at line 34 of file EnvironmentGpuExecutor.cpp.

35 : implementation_(std::make_unique<Impl>())
36{
37 auto& state = *implementation_;
38 // Device libraries bind private runtime symbols at link time, including
39 // absent optional hooks. Ordinary loading preserves driver instrumentation.
40 // The boundary carries plain data and opaque handles; C++ allocation and
41 // exceptions stay in their owner.
42 state.library = dlopen(library.c_str(), RTLD_NOW | RTLD_LOCAL);
43 if (!state.library) throw std::runtime_error(dlerror());
44 const auto create =
45 reinterpret_cast<decltype(&gpr_stdpar_environment_create_v1)>(
46 dlsym(state.library, "gpr_stdpar_environment_create_v1"));
47 state.destroy = reinterpret_cast<Impl::Destroy>(
48 dlsym(state.library, "gpr_stdpar_environment_destroy_v1"));
49 state.assemble = reinterpret_cast<Impl::Assemble>(
50 dlsym(state.library, "gpr_stdpar_environment_blocks_v1"));
51 if (!create || !state.destroy || !state.assemble)
52 throw std::runtime_error("incompatible environment GPU library");
53 char error[1024]{};
54 state.workspace = create(error, sizeof(error));
55 if (!state.workspace) throw std::runtime_error(error);
56}
void * gpr_stdpar_environment_create_v1(char *error, std::size_t capacity) noexcept
decltype(&gpr_stdpar_environment_blocks_v1) Assemble
decltype(&gpr_stdpar_environment_destroy_v1) Destroy

◆ ~EnvironmentGpuExecutor()

gpr::linalg::EnvironmentGpuExecutor::~EnvironmentGpuExecutor ( )
default

◆ EnvironmentGpuExecutor() [2/2]

gpr::linalg::EnvironmentGpuExecutor::EnvironmentGpuExecutor ( const EnvironmentGpuExecutor & )
delete

Member Function Documentation

◆ assemble()

void gpr::linalg::EnvironmentGpuExecutor::assemble ( const gpr::detail::EnvironmentPairBatch & batch,
std::span< double > output ) const

Definition at line 60 of file EnvironmentGpuExecutor.cpp.

63{
64 if (batch.channel_count <= 0 || batch.left.dimensions <= 0 ||
65 batch.right.dimensions <= 0)
66 throw std::invalid_argument("invalid environment output dimensions");
67 std::size_t required = batch.pair_count;
68 for (const std::size_t extent: {std::size_t(batch.channel_count),
69 std::size_t(batch.left.dimensions) + 1,
70 std::size_t(batch.right.dimensions) + 1}) {
71 if (required > std::numeric_limits<std::size_t>::max() / extent)
72 throw std::length_error("environment output dimensions overflow");
73 required *= extent;
74 }
75 if (output.size() != required)
76 throw std::invalid_argument("environment output size differs");
77 char error[1024]{};
78 if (implementation_->assemble(implementation_->workspace, &batch,
79 output.data(), error, sizeof(error)))
80 throw std::runtime_error(error);
81}

◆ operator=()

EnvironmentGpuExecutor & gpr::linalg::EnvironmentGpuExecutor::operator= ( const EnvironmentGpuExecutor & )
delete

The documentation for this class was generated from the following files: