Skip to content

Commit

Permalink
Removed Debugging Code from naive_progam (#58)
Browse files Browse the repository at this point in the history
* Removed Debugging Statement

* Removed Debugging Code from naive_progam, Enhanced Functionality, and Added Additional Unit Tests
  • Loading branch information
coreylammie authored Jun 25, 2021
1 parent 4e13843 commit aa54b63
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 16 deletions.
45 changes: 29 additions & 16 deletions memtorch/bh/crossbar/Program.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def naive_program(
neg_voltage_level=-1.0,
timeout=5,
force_adjustment=1e-3,
force_adjustment_rel_tol=1e-1,
force_adjustment_pos_voltage_threshold=0,
force_adjustment_neg_voltage_threshold=0,
simulate_neighbours=True,
):
"""Method to program (alter) the conductance of a given device within a crossbar.
Expand All @@ -45,6 +48,12 @@ def naive_program(
Timeout (seconds) until stuck devices are unstuck.
force_adjustment : float
Adjustment (resistance) to unstick stuck devices.
force_adjustment_rel_tol : float
Relative tolerance threshold between a stuck device's conductance and high and low conductance states to force adjust.
force_adjustment_pos_voltage_threshold : float
Positive voltage level threshold (V) to enable force adjustment.
force_adjustment_neg_voltage_threshold : float
Negative voltage level threshold (V) to enable force adjustment.
simulate_neighbours : bool
Simulate neighbours (True).
Expand Down Expand Up @@ -111,22 +120,26 @@ def naive_program(
crossbar.devices[idx].simulate(voltage_signal / 2)

if crossbar.devices[point].g == previous_g:
idx = np.argmin(
[
abs((1 / previous_g) - crossbar.devices[point].r_on),
abs((1 / previous_g) - crossbar.devices[point].r_off),
]
)
if idx == 0:
crossbar.devices[point].set_conductance(
crossbar.devices[point].g - force_adjustment
)
else:
crossbar.devices[point].set_conductance(
crossbar.devices[point].g + force_adjustment
)
print(crossbar.devices[point].g)
exit(0)
if (
np.amax(voltage_signal) >= force_adjustment_pos_voltage_threshold
or np.amin(voltage_signal) <= force_adjustment_neg_voltage_threshold
):
if math.isclose(
previous_g,
1 / crossbar.devices[point].r_on,
rel_tol=force_adjustment_rel_tol,
):
crossbar.devices[point].set_conductance(
crossbar.devices[point].g - force_adjustment
)
elif math.isclose(
previous_g,
1 / crossbar.devices[point].r_off,
rel_tol=force_adjustment_rel_tol,
):
crossbar.devices[point].set_conductance(
crossbar.devices[point].g + force_adjustment
)

iterations += 1
if iterations % 100 == 0 and time.time() > timeout:
Expand Down
19 changes: 19 additions & 0 deletions tests/test_crossbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ def test_crossbar(shape):
device = torch.device("cpu" if "cpu" in memtorch.__version__ else "cuda")
memristor_model = memtorch.bh.memristor.LinearIonDrift
memristor_model_params = {"time_series_resolution": 1e-3}
pos_crossbar = memtorch.bh.crossbar.Crossbar(
memristor_model, memristor_model_params, shape
)
pos_crossbar.devices[0][0].g = 1 / pos_crossbar.r_off_mean
pos_crossbar.devices[0][1].g = 1 / pos_crossbar.r_on_mean
neg_crossbar = copy.deepcopy(pos_crossbar)
pos_conductance_matrix, neg_conductance_matrix = naive_map(
torch.zeros(shape).uniform_(0, 1),
memristor_model().r_on,
memristor_model().r_off,
memtorch.bh.crossbar.Scheme.DoubleColumn,
)
pos_crossbar.write_conductance_matrix(
pos_conductance_matrix, transistor=False, programming_routine=naive_program
)
neg_crossbar.write_conductance_matrix(
pos_conductance_matrix, transistor=False, programming_routine=naive_program
)

crossbar = memtorch.bh.crossbar.Crossbar(
memristor_model, memristor_model_params, shape
)
Expand Down

0 comments on commit aa54b63

Please sign in to comment.