Skip to content

tenzr::VariableNode

More...

#include <node.h>

Inherits from tenzr::Node, std::enable_shared_from_this< Node >

Public Functions

Name
VariableNode(Shape shape, DType dtype, std::string name ="", ShardingSpec sharding =ShardingSpec::Replicated())
virtual std::string OpName() const override
StableHLO-style name of this node's operation.
const std::string & VariableName() const
Optional human-readable variable name.
void SetData(std::shared_ptr< PinnedBuffer > data)
Bind host storage.
const std::shared_ptr< PinnedBuffer > & Data() const
The bound host storage, if any.
bool HasData() const
Whether host storage is bound.
void SetDeviceData(std::shared_ptr< DeviceBuffer > device_data)
Bind device storage.
const std::shared_ptr< DeviceBuffer > & DeviceData() const
The bound device storage, if any.
bool HasDeviceData() const
Whether device storage is bound.
void SyncHost()
Copy device data back into host storage.
void SyncDevice()
Upload host data to device storage.

Additional inherited members

Public Functions inherited from tenzr::Node

Name
Node(NodeKind kind, Shape shape, DType dtype, ShardingSpec sharding =ShardingSpec::Replicated())
virtual ~Node() =default
NodeKind Kind() const
The node's operation kind.
const Shape & shape() const
The node's output shape.
DType Dtype() const
The node's output dtype.
const ShardingSpec & Sharding() const
The node's sharding spec.
void SetSharding(ShardingSpec spec)
Replace the sharding spec.
const StridedLayout & Layout() const
The node's strided layout.
void SetLayout(StridedLayout layout)
Replace the layout.
const std::vector< std::shared_ptr< Node > > & Inputs() const
The node's input operands.
uint64_t Id() const
The node's unique id.

Protected Functions inherited from tenzr::Node

Name
uint64_t NextId()

Protected Attributes inherited from tenzr::Node

Name
NodeKind kind_
Shape shape_
DType dtype_
ShardingSpec sharding_
StridedLayout layout_
std::vector< std::shared_ptr< Node > > inputs_
uint64_t id_

Detailed Description

class tenzr::VariableNode;

Leaf node holding a named variable and its optional host and device storage.

Public Functions Documentation

function VariableNode

VariableNode(
    Shape shape,
    DType dtype,
    std::string name ="",
    ShardingSpec sharding =ShardingSpec::Replicated()
)

Parameters:

  • shape Variable shape.
  • dtype Variable dtype.
  • name Optional debug name.
  • sharding Sharding of the variable.

Create a variable (leaf) node, defaulting its name from the node id when empty.

function OpName

inline virtual std::string OpName() const override

StableHLO-style name of this node's operation.

Reimplements: tenzr::Node::OpName

function VariableName

inline const std::string & VariableName() const

Optional human-readable variable name.

function SetData

void SetData(
    std::shared_ptr< PinnedBuffer > data
)

Bind host storage.

Parameters:

  • data Host buffer to attach.

Bind host data and drop any cached device buffer.

function Data

const std::shared_ptr< PinnedBuffer > & Data() const

The bound host storage, if any.

Return: Reference to the host buffer.

Host buffer, copying it back from the device on demand.

function HasData

bool HasData() const

Whether host storage is bound.

Return: true when either buffer exists.

Whether host or device data is present.

function SetDeviceData

void SetDeviceData(
    std::shared_ptr< DeviceBuffer > device_data
)

Bind device storage.

Parameters:

  • device_data Device buffer to attach.

Bind a device buffer.

function DeviceData

const std::shared_ptr< DeviceBuffer > & DeviceData() const

The bound device storage, if any.

Return: Reference to the device buffer.

Device buffer bound to this variable.

function HasDeviceData

bool HasDeviceData() const

Whether device storage is bound.

Return: true when device data exists.

Whether a device buffer is present.

function SyncHost

void SyncHost()

Copy device data back into host storage.

Copy the device buffer back into a pooled host buffer.

function SyncDevice

void SyncDevice()

Upload host data to device storage.

Upload the host buffer to the device, canonicalizing strided data first.