PXL
pxl::Launcher Class Reference

Execution context for kernel launches on XCENA devices. More...

#include <launcher.hpp>

Public Member Functions

 Launcher ()
 Constructs a Launcher with deferred device detection. More...
 
 Launcher (uint32_t deviceId)
 Constructs a Launcher for an explicit device ID. More...
 
 ~Launcher ()
 
 Launcher (const Launcher &)=delete
 
Launcher & operator= (const Launcher &)=delete
 
 Launcher (Launcher &&) noexcept
 
Launcher & operator= (Launcher &&) noexcept
 
template<auto Func, typename... Args, detail::EnableCompatibleKernelArguments< Func, Args... > = 0>
LaunchBuilder execute (uint32_t taskCount, Args &&... args)
 Launches a kernel for deferred execution. More...
 
template<auto Func, typename... Args, detail::EnableCompatibleKernelArguments< Func, Args... > = 0>
detail::TaskCountRequired< LaunchBuilder > execute (Args &&... args)
 Launches a kernel with only the kernel's own arguments. More...
 
template<auto Func, typename... Args, detail::EnableCompatibleKernelArguments< Func, Args... > = 0>
StageBuilder stage (uint32_t taskCount, Args &&... args)
 Begins a stage chain with a sequential kernel stage. More...
 
template<auto Func, typename... Args, detail::EnableCompatibleKernelArguments< Func, Args... > = 0>
detail::TaskCountRequired< StageBuilder > stage (Args &&... args)
 Begins a stage chain with only the kernel's own arguments. More...
 
StageGroupBuilder stage ()
 Begins a parallel stage group. More...
 
uint32_t deviceId () const
 Returns the device ID. More...
 
bool isValid () const
 Returns whether the launcher was initialized successfully. More...
 

Detailed Description

Execution context for kernel launches on XCENA devices.

Provides kernel launch capabilities. Device is either specified explicitly or auto-detected from the first pointer argument in execute()/pipeline().

Example usage:

auto* A = pxl::allocateMemory<int>(0, 1024);
auto* B = pxl::allocateMemory<int>(0, 1024);
auto result = pxl::Launcher().execute<vectorAdd>(A, B, elementCount).tasks(taskCount).run();
if (result.status != pxl::Result::Success) { ... }
pxl::releaseMemory(A);
pxl::releaseMemory(B);
LaunchResult run()
Executes the kernel and waits for completion.
Execution context for kernel launches on XCENA devices.
Definition: launcher.hpp:267
LaunchBuilder execute(uint32_t taskCount, Args &&... args)
Launches a kernel for deferred execution.
Definition: launcher.hpp:336

Definition at line 266 of file launcher.hpp.

Constructor & Destructor Documentation

◆ Launcher() [1/4]

pxl::Launcher::Launcher ( )

Constructs a Launcher with deferred device detection.

Device selection priority on the first execute()/stage() call:

  1. If any pointer argument was returned by pxl::allocateMemory(), use that pointer's device. Mixed-device pointer args are rejected with a launch-time failure.
  2. Otherwise, fall back to the process-default device cache (see pxl::getDefaultDeviceId() in context.hpp). If the cache is unpopulated, the first computable device is picked and cached ONLY when resolved from a pointer arg — pickDefaultForCompute itself does not clobber a user-set default.
  3. If neither path resolves a device, run()/runAsync() returns pxl::kNoDeviceResolvedMessage.

Once bound on the first call, the device is reused for every subsequent execute()/stage() on the same Launcher; cross-device pointer args are rejected at run()/runAsync() time.

◆ Launcher() [2/4]

pxl::Launcher::Launcher ( uint32_t  deviceId)
explicit

Constructs a Launcher for an explicit device ID.

Use this when all kernel arguments are scalars (no device pointers), or when you want to override the auto-detection logic. The explicit deviceId always wins — even if a pointer argument resolves to a different device, the kernel runs on deviceId (and the cross-device check in run() will surface the mismatch as a launch failure).

Side effect: a successful explicit construction updates the process-wide default device cache (see pxl::getDefaultDeviceId()). Subsequent auto-allocations (allocateMemory(N) without deviceId) and default-Launcher() calls will favor this device until the cache is cleared via pxl::clearDefaultDeviceId().

Parameters
deviceIdTarget device identifier.

◆ ~Launcher()

pxl::Launcher::~Launcher ( )

◆ Launcher() [3/4]

pxl::Launcher::Launcher ( const Launcher &  )
delete

◆ Launcher() [4/4]

pxl::Launcher::Launcher ( Launcher &&  )
noexcept

Member Function Documentation

◆ deviceId()

uint32_t pxl::Launcher::deviceId ( ) const

Returns the device ID.

◆ execute() [1/2]

template<auto Func, typename... Args, detail::EnableCompatibleKernelArguments< Func, Args... > = 0>
detail::TaskCountRequired<LaunchBuilder> pxl::Launcher::execute ( Args &&...  args)
inline

Launches a kernel with only the kernel's own arguments.

Set the task count on the returned builder with .tasks(taskCount). Kernel arity distinguishes this form from the positional compatibility form, including when the kernel's first argument is an integer. The pending return type exposes no run()/runAsync(), so attempting execution before .tasks(taskCount) is a C++ compile error. Discarding the pending request instead produces its [[nodiscard]] diagnostic and executes nothing.

Definition at line 384 of file launcher.hpp.

385  {
386  return detail::TaskCountRequired<LaunchBuilder>(
387  execute<Func>(uint32_t{0}, std::forward<Args>(args)...));
388  }

◆ execute() [2/2]

template<auto Func, typename... Args, detail::EnableCompatibleKernelArguments< Func, Args... > = 0>
LaunchBuilder pxl::Launcher::execute ( uint32_t  taskCount,
Args &&...  args 
)
inline

Launches a kernel for deferred execution.

Template Parameters
FuncKernel function pointer (must have KernelTraits specialization from pxcc).
ArgsKernel argument types.
Parameters
taskCountNumber of tasks to execute.
argsKernel arguments (device memory pointers and scalars).
Returns
LaunchBuilder for chaining .reserve()/.run().

Directional kernel parameters require the exact kernel argument count and a compatible typed pointer or typed NDArray. Raw void* allocations must be cast to the kernel element type (or allocated with allocateMemory<T>()) so element mismatches remain diagnosable.

Warning
A raw pointer passed to an output_ptr parameter makes the entire managed allocation range from that pointer discardable and synchronized back; use an NDArray argument to bound a smaller output view.

Definition at line 336 of file launcher.hpp.

337  {
338  const char* kernelName = nullptr;
339 
340 #if defined(__PXCC_ANALYSIS__)
341  kernelName = "__pxcc_placeholder__";
342 #else
343  static_assert(sizeof(pxl::KernelTraits<Func>) > 0,
344  "Kernel function not found in KernelTraits — was it compiled with pxcc?");
345  kernelName = pxl::KernelTraits<Func>::name;
346 #endif
347 
348  std::vector<ArgInfo_t> argList;
349  std::vector<std::shared_ptr<void>> storage;
350  std::vector<std::pair<void*, size_t>> syncTargets;
351  auto directions = detail::MakeKernelDirections<Func>();
352  argList.reserve(sizeof...(Args));
353  if constexpr (sizeof...(Args) > 0)
354  {
355  buildArgList(argList, storage, syncTargets, std::forward<Args>(args)...);
356  }
357 
358  if (impl_ == nullptr)
359  {
360  initFromArgs(argList, syncTargets);
361  }
362  if (!isValid())
363  {
364  return makeEmptyBuilder();
365  }
366 
367  return execute(kernelName, taskCount,
368  std::move(argList), std::move(storage), std::move(syncTargets),
369  std::move(directions));
370  }
bool isValid() const
Returns whether the launcher was initialized successfully.
Traits class that maps a kernel function pointer to its name string.
Definition: module.hpp:30

◆ isValid()

bool pxl::Launcher::isValid ( ) const

Returns whether the launcher was initialized successfully.

◆ operator=() [1/2]

Launcher& pxl::Launcher::operator= ( const Launcher &  )
delete

◆ operator=() [2/2]

Launcher& pxl::Launcher::operator= ( Launcher &&  )
noexcept

◆ stage() [1/3]

StageGroupBuilder pxl::Launcher::stage ( )
inline

Begins a parallel stage group.

Device is auto-detected from pointer arguments when run() is called.

Example:

auto result = pxl::Launcher()
.stage()
.add<K1>(A, B).tasks(firstTaskCount)
.add<K2>(C, D).tasks(secondTaskCount)
.stage<K3>(E, F).tasks(finalTaskCount)
.run();
StageBuilder stage(uint32_t taskCount, Args &&... args)
Begins a stage chain with a sequential kernel stage.
Definition: launcher.hpp:408
StageBuilder & stage(uint32_t taskCount, Args &&... args)
LaunchResult run()

Definition at line 459 of file launcher.hpp.

460  {
461  // Allocate the parent StageBuilder on the heap and transfer ownership
462  // to the returned StageGroupBuilder. Without owning the parent here,
463  // the StageGroupBuilder would hold a reference into this stack frame
464  // and dangle as soon as the function returns.
465  return StageGroupBuilder(std::make_unique<StageBuilder>(impl_));
466  }

◆ stage() [2/3]

template<auto Func, typename... Args, detail::EnableCompatibleKernelArguments< Func, Args... > = 0>
detail::TaskCountRequired<StageBuilder> pxl::Launcher::stage ( Args &&...  args)
inline

Begins a stage chain with only the kernel's own arguments.

Set the task count for the new stage with .tasks(taskCount). Kernel arity distinguishes this form from the positional compatibility form. The pending return type exposes no run()/runAsync() or next stage operation.

Definition at line 438 of file launcher.hpp.

439  {
440  return detail::TaskCountRequired<StageBuilder>(
441  stage<Func>(uint32_t{0}, std::forward<Args>(args)...));
442  }

◆ stage() [3/3]

template<auto Func, typename... Args, detail::EnableCompatibleKernelArguments< Func, Args... > = 0>
StageBuilder pxl::Launcher::stage ( uint32_t  taskCount,
Args &&...  args 
)
inline

Begins a stage chain with a sequential kernel stage.

Template Parameters
FuncKernel function pointer.
Parameters
taskCountNumber of tasks to execute.
argsKernel arguments.
Returns
StageBuilder for chaining additional stages.

Example:

auto result = pxl::Launcher()
.stage<K1>(data, mid).tasks(taskCount)
.stage<K2>(mid, out).tasks(taskCount)
.run();

Definition at line 408 of file launcher.hpp.

409  {
410  if (impl_ == nullptr)
411  {
412  std::vector<ArgInfo_t> tempArgList;
413  std::vector<std::shared_ptr<void>> tempStorage;
414  std::vector<std::pair<void*, size_t>> tempSyncTargets;
415  tempArgList.reserve(sizeof...(Args));
416  if constexpr (sizeof...(Args) > 0)
417  {
418  buildArgList(tempArgList, tempStorage, tempSyncTargets, std::forward<Args>(args)...);
419  }
420  initFromArgs(tempArgList, tempSyncTargets);
421  }
422  StageBuilder builder(impl_);
423  // Call returns StageBuilder& to the local; discard ref and return the
424  // local by value to enable NRVO (StageBuilder is move-only).
425  builder.stage<Func>(taskCount, std::forward<Args>(args)...);
426  return builder;
427  }

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