File size: 1,581 Bytes
520d6cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""

Multicore system simulation for virtual GPU v2.

Simulates 50,000 identical AdvancedCore instances in parallel.

"""

from core import AdvancedCore

class MultiCoreSystem:
    def __init__(self, num_cores=50000, bits=2, num_registers=2):
        self.cores = [AdvancedCore(bits=bits, num_registers=num_registers) for _ in range(num_cores)]
        self.num_cores = num_cores

    def step_all(self, a, b, cin, opcode, reg_sel):
        """

        Steps all cores in parallel with the same input.

        a, b: lists of voltages (length 2)

        cin: carry in

        opcode: ALU operation

        reg_sel: register select

        Returns: list of results from all cores

        """
        return [core.step(a, b, cin, opcode, reg_sel) for core in self.cores]

    def step_all_custom(self, inputs):
        """

        Steps all cores in parallel with custom input for each core.

        inputs: list of dicts with keys 'a', 'b', 'cin', 'opcode', 'reg_sel'

        Returns: list of results from all cores

        """
        return [core.step(inp['a'], inp['b'], inp['cin'], inp['opcode'], inp['reg_sel']) for core, inp in zip(self.cores, inputs)]

if __name__ == "__main__":
    print("\n--- MultiCore System Simulation (50,000 cores) ---")
    system = MultiCoreSystem(num_cores=50000, bits=2, num_registers=2)
    # Example: Step all cores with the same ADD operation
    results = system.step_all([0.7, 0.0], [0.7, 0.7], 0.0, 0b10, 0)
    print(f"First core result: {results[0]}")
    print(f"Total cores simulated: {len(results)}")