def testCorrelation(): # Instantiate processor proc = emulatedHw(N,M,IB_DEPTH,FUVRF_SIZE,VVVRF_SIZE,TB_SIZE,MAX_CHAINS,BUILDING_BLOCKS) fw = firm.correlation(proc.compiler) # Feed one value to input buffer np.random.seed(0) input_vector1=np.random.rand(N)*8-4 input_vector2=np.random.rand(N)*8-4 proc.push([input_vector1,False]) proc.push([input_vector2,True]) # Step through it until we get the result proc.config(fw) tb = proc.run() # Note that this is the Cross-correlation of two 1-dimensional sequences, not the coeficient numpy_correlate = np.corrcoef(input_vector1,input_vector2) v = proc.dp.v_out x, y, xx, yy, xy = v[1], v[4], v[2], v[5], v[3] # Note that the equation in this website is wrong, but the math is correct # https://www.investopedia.com/terms/c/correlation.asp corr = (N*xy-x*y)/math.sqrt((N*xx-x*x)*(N*yy-y*y)) assert np.isclose(numpy_correlate[0][1],corr), "Correlation matches" print("Passed test #5")
def testSummaryStats(): # Instantiate processor proc = emulatedHw(N,M,IB_DEPTH,FUVRF_SIZE,VVVRF_SIZE,TB_SIZE,MAX_CHAINS,BUILDING_BLOCKS) proc.fu.vrf=list(np.concatenate(([0.,float('inf')],list(reversed(range(FUVRF_SIZE*M-2)))))) # Initializing fuvrf for sparsity fw = firm.summaryStats(proc.compiler) # Feed one value to input buffer np.random.seed(0) input_vector1=np.random.rand(N)*8-4 input_vector2=np.random.rand(N)*8-4 proc.push([input_vector1,False]) proc.push([input_vector1,False]) proc.push([input_vector1,False]) proc.push([input_vector1,False]) proc.push([input_vector1,False]) proc.push([input_vector1,False]) proc.push([input_vector1,False]) proc.push([input_vector2,True]) # Step through it until we get the result proc.config(fw) log = proc.run() assert np.isclose(proc.dp.v_out[0],np.sum(input_vector1)*7+np.sum(input_vector2)), "Reduce sum failed" assert 47==int(proc.dp.v_out[1]), "Sparsity sum failed" print("Passed test #3")
def raw(): # Instantiate HW and Emulator Processors readConf() hw_proc = rtlHw(N, M, IB_DEPTH, FUVRF_SIZE, VVVRF_SIZE, TB_SIZE, DATA_WIDTH, MAX_CHAINS, BUILDING_BLOCKS, DATA_TYPE, DEVICE_FAM) emu_proc = emulatedHw(N, M, IB_DEPTH, FUVRF_SIZE, VVVRF_SIZE, TB_SIZE, MAX_CHAINS, BUILDING_BLOCKS) # Create common input values num_input_vectors = 3 pushVals(emu_proc, hw_proc, num_input_vectors, neg_vals=True) # Configure firmware - Both HW and Emulator work with the same firmware fw = firm.raw(hw_proc.compiler) emu_proc.config(fw) hw_proc.config(fw) # Run HW simulation and emulation steps = 30 hw_results = hw_proc.run(steps=steps, gui=False, log=False) emu_results = emu_proc.run(steps=steps) # Filter Results emu_results_filtered, hw_results_filtered = filterResults( emu_results, hw_results, DATA_TYPE) # Verify that results are equal assert np.allclose(emu_results_filtered, hw_results_filtered, rtol=0.01) print("Passed test #1")
def testSimpleDistribution(): # Instantiate processor proc = emulatedHw(N,M,IB_DEPTH,FUVRF_SIZE,VVVRF_SIZE,TB_SIZE,MAX_CHAINS,BUILDING_BLOCKS) # Initial hardware setup proc.fu.vrf=list(range(FUVRF_SIZE*M)) # Initializing fuvrf fw = firm.distribution(proc.compiler,bins=2*M,M=M) # Feed one value to input buffer np.random.seed(42) input_vector = np.random.rand(N)*8 proc.push([input_vector,True]) # Step through it until we get the result proc.config(fw) log = proc.run() assert np.allclose(log['tb'][-1][0],[ 1.,2.,1.,0.,1.,1.,1.,1.]), "Test with distribution failed" print("Passed test #1")
def testSpatialSparsity(): # Instantiate processor proc = emulatedHw(N,M,IB_DEPTH,FUVRF_SIZE,VVVRF_SIZE,TB_SIZE,MAX_CHAINS,BUILDING_BLOCKS) proc.fu.vrf=list(np.concatenate(([0.,float('inf')],list(reversed(range(FUVRF_SIZE*M-2)))))) # Initializing fuvrf for sparsity fw = firm.spatialSparsity(proc.compiler,N) # Feed one value to input buffer np.random.seed(0) input_vector1=np.random.rand(N)*8-4 input_vector2=np.random.rand(N)*8-4 proc.push([input_vector1,False]) proc.push([input_vector2,True]) # Step through it until we get the result proc.config(fw) log = proc.run() assert np.isclose(log['tb'][-1][0],[ 1.,1.,1.,1.,0.,1.,0.,1.]).all(), "Spatial Sparsity Failed" assert np.isclose(log['tb'][-1][1],[ 1.,0.,1.,1.,1.,1.,0.,0.]).all(), "Spatial Sparsity Failed" print("Passed test #4")
def testVectorChange(): # Instantiate processor proc = emulatedHw(N,M,IB_DEPTH,FUVRF_SIZE,VVVRF_SIZE,TB_SIZE,MAX_CHAINS,BUILDING_BLOCKS) fw = firm.vectorChange(proc.compiler) # Feed value to input buffer np.random.seed(0) input_vector1=np.random.rand(N)*8-4 input_vector2=np.random.rand(N)*8-4 proc.push([input_vector1,False]) proc.push([input_vector2,True]) # Step through it until we get the result proc.config(fw) tb = proc.run() assert np.isclose(np.sum(input_vector2-input_vector1),proc.dp.v_out[1]) print("Passed test #6")
def predictiveness(): # Instantiate HW and Emulator Processors readConf() DATA_TYPE = 'int' BUILDING_BLOCKS = [ 'InputBuffer', 'FilterReduceUnit', 'VectorScalarReduce', 'VectorVectorALU', 'DataPacker', 'TraceBuffer' ] hw_proc = rtlHw(N, M, IB_DEPTH, FUVRF_SIZE, VVVRF_SIZE, TB_SIZE, DATA_WIDTH, MAX_CHAINS, BUILDING_BLOCKS, DATA_TYPE, DEVICE_FAM) emu_proc = emulatedHw(N, M, IB_DEPTH, FUVRF_SIZE, VVVRF_SIZE, TB_SIZE, MAX_CHAINS, BUILDING_BLOCKS) # Create common input values num_input_vectors = 4 eof1 = [False, True, False, True] eof2 = [False, False, False, True] pushVals(emu_proc, hw_proc, num_input_vectors, eof1, eof2) # Configure firmware - Both HW and Emulator work with the same firmware fw = firm.activationPredictiveness(hw_proc.compiler) emu_proc.config(fw) hw_proc.config(fw) # Run HW simulation and emulation steps = 45 hw_results = hw_proc.run(steps=steps, gui=False, log=False) emu_results = emu_proc.run(steps=steps) # Filter Results emu_results_filtered, hw_results_filtered = filterResults( emu_results, hw_results, DATA_TYPE) # Verify that results are equal assert np.allclose(emu_results_filtered, hw_results_filtered, rtol=0.05) print("Passed test #7")
def distribution(): # Instantiate HW and Emulator Processors readConf() hw_proc = rtlHw(N, M, IB_DEPTH, FUVRF_SIZE, VVVRF_SIZE, TB_SIZE, DATA_WIDTH, MAX_CHAINS, BUILDING_BLOCKS, DATA_TYPE, DEVICE_FAM) emu_proc = emulatedHw(N, M, IB_DEPTH, FUVRF_SIZE, VVVRF_SIZE, TB_SIZE, MAX_CHAINS, BUILDING_BLOCKS) # Create common input values num_input_vectors = 2 eof1 = num_input_vectors * [True] pushVals(emu_proc, hw_proc, num_input_vectors, eof1) # Initialize the memories the same way emu_proc.initialize_fu = list(range(FUVRF_SIZE * M)) hw_proc.initialize_fu = list(range(FUVRF_SIZE * M)) # Configure firmware - Both HW and Emulator work with the same firmware fw = firm.distribution(hw_proc.compiler, 16, 4) emu_proc.config(fw) hw_proc.config(fw) # Run HW simulation and emulation steps = 45 hw_results = hw_proc.run(steps=steps, gui=False, log=False) emu_results = emu_proc.run(steps=steps) # Filter Results emu_results_filtered, hw_results_filtered = filterResults( emu_results, hw_results, DATA_TYPE) # Verify that results are equal assert np.allclose(emu_results_filtered, hw_results_filtered) print("Passed test #5")