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:279
LaunchBuilder execute(uint32_t taskCount, Args &&... args)
Launches a kernel for deferred execution.
Definition: launcher.hpp:355

Definition at line 278 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 becomes the process default. A cached default that is not computable is kept; the first computable device is bound to this Launcher instead. A device resolved in step 1 becomes the process default, replacing any earlier one, except in stage() group chains.
  3. If neither path resolves a device, run()/runAsync() returns pxl::kNoDeviceResolvedMessage.

Host memory (malloc, stack, static) cannot be a pointer argument: it names no device, and run()/runAsync() refuses it with Result::InvalidArgument and pxl::kHostMemoryArgumentMessage (a stage chain appends the kernel name).

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 403 of file launcher.hpp.

404  {
405  return detail::TaskCountRequired<LaunchBuilder>(
406  execute<Func>(uint32_t{0}, std::forward<Args>(args)...));
407  }

◆ 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 355 of file launcher.hpp.

356  {
357  const char* kernelName = nullptr;
358 
359 #if defined(__PXCC_ANALYSIS__)
360  kernelName = "__pxcc_placeholder__";
361 #else
362  static_assert(sizeof(pxl::KernelTraits<Func>) > 0,
363  "Kernel function not found in KernelTraits — was it compiled with pxcc?");
364  kernelName = pxl::KernelTraits<Func>::name;
365 #endif
366 
367  std::vector<ArgInfo_t> argList;
368  std::vector<std::shared_ptr<void>> storage;
369  std::vector<std::pair<void*, size_t>> syncTargets;
370  auto directions = detail::MakeKernelDirections<Func>();
371  argList.reserve(sizeof...(Args));
372  if constexpr (sizeof...(Args) > 0)
373  {
374  buildArgList(argList, storage, syncTargets, std::forward<Args>(args)...);
375  }
376 
377  if (impl_ == nullptr)
378  {
379  initFromArgs(argList, syncTargets);
380  }
381  if (!isValid())
382  {
383  return makeEmptyBuilder();
384  }
385 
386  return execute(kernelName, taskCount,
387  std::move(argList), std::move(storage), std::move(syncTargets),
388  std::move(directions));
389  }
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:32

◆ 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:427
StageBuilder & stage(uint32_t taskCount, Args &&... args)
LaunchResult run()

Definition at line 478 of file launcher.hpp.

479  {
480  // Allocate the parent StageBuilder on the heap and transfer ownership
481  // to the returned StageGroupBuilder. Without owning the parent here,
482  // the StageGroupBuilder would hold a reference into this stack frame
483  // and dangle as soon as the function returns.
484  return StageGroupBuilder(std::make_unique<StageBuilder>(impl_));
485  }

◆ 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 457 of file launcher.hpp.

458  {
459  return detail::TaskCountRequired<StageBuilder>(
460  stage<Func>(uint32_t{0}, std::forward<Args>(args)...));
461  }

◆ 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 427 of file launcher.hpp.

428  {
429  if (impl_ == nullptr)
430  {
431  std::vector<ArgInfo_t> tempArgList;
432  std::vector<std::shared_ptr<void>> tempStorage;
433  std::vector<std::pair<void*, size_t>> tempSyncTargets;
434  tempArgList.reserve(sizeof...(Args));
435  if constexpr (sizeof...(Args) > 0)
436  {
437  buildArgList(tempArgList, tempStorage, tempSyncTargets, std::forward<Args>(args)...);
438  }
439  initFromArgs(tempArgList, tempSyncTargets);
440  }
441  StageBuilder builder(impl_);
442  // Call returns StageBuilder& to the local; discard ref and return the
443  // local by value to enable NRVO (StageBuilder is move-only).
444  builder.stage<Func>(taskCount, std::forward<Args>(args)...);
445  return builder;
446  }

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