phanerozoic commited on
Commit
32a7f56
·
verified ·
1 Parent(s): 65aa579

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +16 -0
  2. config.json +9 -0
  3. create_safetensors.py +60 -0
  4. model.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - pytorch
5
+ - safetensors
6
+ - threshold-logic
7
+ - neuromorphic
8
+ ---
9
+
10
+ # threshold-fifo-ctrl
11
+
12
+ fifo-ctrl threshold logic implementation.
13
+
14
+ ## License
15
+
16
+ MIT
config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "threshold-fifo-ctrl",
3
+ "description": "fifo-ctrl circuit",
4
+ "inputs": 8,
5
+ "outputs": 8,
6
+ "neurons": 8,
7
+ "layers": 2,
8
+ "parameters": 64
9
+ }
create_safetensors.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from safetensors.torch import save_file
3
+
4
+ weights = {}
5
+
6
+ # FIFO Controller (4-entry)
7
+ # Manages read/write pointers and full/empty flags
8
+
9
+ def add_neuron(name, w_list, bias):
10
+ weights[f'{name}.weight'] = torch.tensor([w_list], dtype=torch.float32)
11
+ weights[f'{name}.bias'] = torch.tensor([bias], dtype=torch.float32)
12
+
13
+ # Input: WR_PTR[1:0], RD_PTR[1:0], WRITE, READ (6 bits)
14
+ # Output: NEW_WR_PTR[1:0], NEW_RD_PTR[1:0], FULL, EMPTY
15
+
16
+ # Pointer increment logic
17
+ add_neuron('wr_inc', [0.0, 0.0, 0.0, 0.0, 1.0, 0.0], -1.0) # WRITE
18
+ add_neuron('rd_inc', [0.0, 0.0, 0.0, 0.0, 0.0, 1.0], -1.0) # READ
19
+
20
+ # Full: WR_PTR+1 == RD_PTR
21
+ # Empty: WR_PTR == RD_PTR
22
+ add_neuron('ptrs_equal', [1.0, 1.0, -1.0, -1.0, 0.0, 0.0], 0.0)
23
+
24
+ save_file(weights, 'model.safetensors')
25
+
26
+ def fifo_ctrl(wr1, wr0, rd1, rd0, write, read):
27
+ wr = wr1*2 + wr0
28
+ rd = rd1*2 + rd0
29
+
30
+ if write:
31
+ wr = (wr + 1) % 4
32
+ if read:
33
+ rd = (rd + 1) % 4
34
+
35
+ empty = 1 if wr == rd else 0
36
+ full = 1 if (wr + 1) % 4 == rd else 0
37
+
38
+ return (wr>>1)&1, wr&1, (rd>>1)&1, rd&1, full, empty
39
+
40
+ print("Verifying FIFO controller...")
41
+ errors = 0
42
+ for wr in range(4):
43
+ for rd in range(4):
44
+ for ops in range(4):
45
+ write, read = (ops>>1)&1, ops&1
46
+ wr1, wr0 = (wr>>1)&1, wr&1
47
+ rd1, rd0 = (rd>>1)&1, rd&1
48
+ result = fifo_ctrl(wr1, wr0, rd1, rd0, write, read)
49
+ # Basic sanity
50
+ if result[4] and result[5]: # Can't be both full and empty
51
+ errors += 1
52
+
53
+ if errors == 0:
54
+ print("All test cases passed!")
55
+ else:
56
+ print(f"FAILED: {errors} errors")
57
+
58
+ mag = sum(t.abs().sum().item() for t in weights.values())
59
+ print(f"Magnitude: {mag:.0f}")
60
+ print(f"Parameters: {sum(t.numel() for t in weights.values())}")
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:25e3a8ec4286b72080d65c87ab1449fb4c67ec536dc6d36afc6de566dd5a7536
3
+ size 500