NVIDIA Holoscan SDK v3.0.0

Class ThreadPool

Base Type

class ThreadPool : public holoscan::gxf::GXFSystemResourceBase

Thread pool resource.

This is a thread pool for use with the EventBasedScheduler or MultiThreadScheduler. This resource should be created via the Fragment::make_thread_pool method instead of the usual Fragment::make_resource method as it requires additional configuration of an associated GXF EntityGroup.

pool1 = make_thread_pool(“pool1”, Arg(“initial_size”, static_cast<int64_t>(2)));

The operators can be added via the add method. For strict thread pinning, the pin_operator argument should be true and the initial_size of the thread pool should be at least as large as the number of operators that will be pinned to threads.

pool1.add(op1, true); pool1.add(op2, true);

This add method takes care of adding any needed holoscan::CPUThread resource to the operator.

The MultiThreadScheduler’s strict_job_thread_pinning argument can be set true to disallow execution of any other entities on the pinned thread. The EventBasedScheduler always uses strict thread pinning.

Public Functions

template<typename ArgT, typename ...ArgsT, typename = std::enable_if_t<!std::is_base_of_v<::holoscan::Resource, std::decay_t<ArgT>> && (std::is_same_v<::holoscan::Arg, std::decay_t<ArgT>> || std::is_same_v<::holoscan::ArgList, std::decay_t<ArgT>>)>>
inline explicit ThreadPool(ArgT &&arg, ArgsT&&... args)
ThreadPool() = default
ThreadPool(const std::string &name, nvidia::gxf::ThreadPool *component)
inline virtual const char *gxf_typename() const override

The underlying GXF component’s name.

virtual void setup(ComponentSpec &spec) override

Define the resource specification.

Parameters

spec – The reference to the component specification.

int64_t size() const

The number of threads currently in the thread pool.

void add(const std::shared_ptr<Operator> &op, bool pin_operator = true)

Add an operator to the thread pool.

Parameters
  • op – The operator to add.

  • pin_operator – Whether the operator should be pinned to a specific thread in the pool.

void add(std::vector<std::shared_ptr<Operator>> ops, bool pin_operator = true)

Add multiple operators to the thread pool.

Parameters
  • op – The operators to add.

  • pin_operator – Whether the operators should be pinned to a specific thread in the pool.

inline std::shared_ptr<gxf::EntityGroup> entity_group() const
inline std::vector<std::shared_ptr<Operator>> operators() const

The operators associated with this thread pool.

virtual YAML::Node to_yaml_node() const override

Get a YAML representation of the thread pool.

Returns

YAML node including properties of the base resource and the operators in the pool.

Protected Functions

inline void entity_group(const std::shared_ptr<gxf::EntityGroup> &entity_group)

Set the entity group for this thread pool.

Friends

friend class Fragment

Previous Class TensorMap
Next Class Timer
© Copyright 2022-2025, NVIDIA. Last updated on Mar 12, 2025.