xbtorch.devices.base

Base device classes for crossbar simulations.

This module provides abstract and concrete device models used to simulate non-ideal analog memory devices. It defines the GenericDevice base class and two primary implementations:

These classes handle conductance-to-weight conversion, pulse-based writes, device-to-device (d2d) and cycle-to-cycle (c2c) variations, and nonlinear weight update behavior.

Notes

All device classes assume that weight_range is defined globally via get_xbtorch_param(). The write methods modify tensors in-place and enforce device conductance bounds.

Classes

AnalyticalDevice(min_conductance, ...)

Analytical nonlinear device model.

GenericDevice([min_conductance, ...])

Abstract base class for analog memory devices.

TabularDevice(reset_g, reset_dg, reset_cdf, ...)

Device model using tabulated empirical measurements.

class xbtorch.devices.base.AnalyticalDevice(min_conductance, max_conductance, d2d_var, c2c_var, nonlinearity_set, nonlinearity_reset, max_level)[source]

Bases: GenericDevice

Analytical nonlinear device model.

Uses exponential nonlinear weight update functions and supports device-to-device (d2d) and cycle-to-cycle (c2c) variations.

Parameters:
  • min_conductance (float) – Minimum conductance.

  • max_conductance (float) – Maximum conductance.

  • d2d_var (float) – Device-to-device variation.

  • c2c_var (float) – Cycle-to-cycle variation.

  • nonlinearity_set (float) – Nonlinearity of set operation.

  • nonlinearity_reset (float) – Nonlinearity of reset operation.

  • max_level (int) – Maximum number of pulse levels.

conductance_to_pulse(G, A, B)[source]

Inverse of pulse_to_conductance: map conductance to pulse position.

Parameters:
  • G (torch.Tensor) – Conductance tensor.

  • A (torch.Tensor) – Parameter A.

  • B (torch.Tensor) – Parameter B.

Returns:

Pulse position tensor.

Return type:

torch.Tensor

data_dir = 'analytical'
get_param_A(nonlinearity)[source]

Get parameter A from nonlinearity using tabulated data (based on DNN + NeuroSim v2).

Parameters:

nonlinearity (torch.Tensor) – Nonlinearity tensor.

Returns:

Parameter A tensor.

Return type:

torch.Tensor

get_param_B(A)[source]

Compute parameter B from A and max/min conductance.

Parameters:

A (torch.Tensor) – Parameter A tensor.

Returns:

Parameter B tensor.

Return type:

torch.Tensor

pulse_to_conductance(xPulse, A, B)[source]

Map pulse position to conductance using nonlinear function.

Parameters:
  • xPulse (torch.Tensor) – Pulse position tensor.

  • A (torch.Tensor) – Parameter A.

  • B (torch.Tensor) – Parameter B.

Returns:

Conductance tensor.

Return type:

torch.Tensor

reset_cached_params()[source]

Reset cached parameters for pulse-conductance calculations.

set_c2c_var(var)[source]

Set cycle-to-cycle variation.

set_d2d_var(var)[source]

Set device-to-device variation.

set_nonlinearity_reset(nl_reset)[source]

Set nonlinearity for reset operation.

set_nonlinearity_set(nl_set)[source]

Set nonlinearity for set operation.

write(G, numPulse, group_param_idx=(0, 0))[source]

Apply pulses to update the device conductance tensor.

Parameters:
  • G (torch.Tensor) – Conductance tensor to update.

  • numPulse (torch.Tensor) – Number of pulses for each element.

  • group_param_idx (tuple, optional) – Index used for parameter caching (default: (0, 0)).

Returns:

Updated conductance tensor.

Return type:

torch.Tensor

class xbtorch.devices.base.GenericDevice(min_conductance=None, max_conductance=None, min_conductance_set=None, min_conductance_reset=None, max_conductance_set=None, max_conductance_reset=None)[source]

Bases: object

Abstract base class for analog memory devices.

Handles conversion between software weights and device conductance, gradient-to-pulse conversion, and caching of device parameters.

Parameters:
  • min_conductance (float, optional) – Minimum conductance of the device (used for both set and reset).

  • max_conductance (float, optional) – Maximum conductance of the device (used for both set and reset).

  • min_conductance_set (float, optional) – Minimum conductance during set operation.

  • min_conductance_reset (float, optional) – Minimum conductance during reset operation.

  • max_conductance_set (float, optional) – Maximum conductance during set operation.

  • max_conductance_reset (float, optional) – Maximum conductance during reset operation.

Raises:

ValueError – If insufficient conductance bounds are provided.

conductance_to_weight(conductance)[source]

Convert device conductance back to software weight.

Parameters:

conductance (torch.Tensor) – Conductance tensor.

Returns:

Corresponding software weight tensor.

Return type:

torch.Tensor

gradient_to_pulse(gradient)[source]

Convert a weight gradient to the number of device pulses using stochastic rounding.

Parameters:

gradient (torch.Tensor) – Weight gradient tensor.

Returns:

Integer tensor of pulses.

Return type:

torch.Tensor

reset_cached_params()[source]

Reset cached device parameters.

weight_to_conductance(weight)[source]

Convert a software weight to device conductance.

Parameters:

weight (torch.Tensor) – Software weight tensor.

Returns:

Corresponding conductance tensor.

Return type:

torch.Tensor

abstract write(G, pulse)[source]

Abstract method to apply pulses to update conductance.

Parameters:
  • G (torch.Tensor) – Conductance tensor to update.

  • pulse (torch.Tensor) – Number of pulses to apply.

class xbtorch.devices.base.TabularDevice(reset_g, reset_dg, reset_cdf, set_g, set_dg, set_cdf, max_level)[source]

Bases: GenericDevice

Device model using tabulated empirical measurements.

Uses gTable, dGTable, and cdfTable to simulate stochastic weight updates with cycle-to-cycle variations.

Parameters:
  • reset_g (str) – Path to reset conductance table.

  • reset_dg (str) – Path to reset dG table.

  • reset_cdf (str) – Path to reset CDF table.

  • set_g (str) – Path to set conductance table.

  • set_dg (str) – Path to set dG table.

  • set_cdf (str) – Path to set CDF table.

  • max_level (int) – Maximum pulse level.

data_dir = 'tabular'
write(G, numPulse, group_param_idx=None)[source]

Apply pulses using tabulated device behavior.

Parameters:
  • G (torch.Tensor) – Conductance tensor to update.

  • numPulse (torch.Tensor) – Number of pulses for each element.

  • group_param_idx (None) – Not used for TabularDevice.

Returns:

Updated conductance tensor.

Return type:

torch.Tensor