def _test_half(veclen): """ Tests a set of elementwise operations on a vector half type. """ _config() @dace.program def halftest(A: dace.float16[N], B: dace.float16[N]): return A * B + A A = np.random.rand(24).astype(np.float16) B = np.random.rand(24).astype(np.float16) sdfg = halftest.to_sdfg() sdfg.name = sdfg.name + str(veclen) sdfg.apply_strict_transformations() sdfg.apply_gpu_transformations() # Apply vectorization on each map and count applied applied = 0 for xform in Optimizer(sdfg).get_pattern_matches(patterns=Vectorization, options=dict( vector_len=veclen, postamble=False)): xform.apply(sdfg) applied += 1 assert applied == 2 out = sdfg(A=A, B=B, N=24) assert np.allclose(out, A * B + A)
compute_paths() with open("/Users/benediktschesch/MyEnv/Vectorization_paths.pkl", "rb") as fp: # Unpickling paths = pickle.load(fp) #paths = paths[0:20] count = 0 data_points = [] max_free_symbols = 0 max_params = 0 for file in tqdm(paths): try: sdfg = dace.SDFG.from_file(file) except: print("Not Valid SDFG at: " + str(file)) continue opt = Optimizer(sdfg) vectorization_map_entry = [ i.query_node(sdfg.sdfg_list[i.sdfg_id], i._map_entry) for i in opt.get_pattern_matches(patterns=[Vectorization]) ] for node, state in sdfg.all_nodes_recursive(): if isinstance(node, MapEntry): dic_training = {} if has_dynamic_map_inputs(state, node): continue tasklet = state.out_edges(node)[0].dst if not isinstance(tasklet, Tasklet): continue free_symbols = set() #Get the Free symbols for Memlet in state.in_edges(tasklet) + state.out_edges(tasklet):
def main(): print("\n ==== Program begins ====") print("\n There are %d CPUs on this machine." % multiprocessing.cpu_count()) global MatrixA global MatrixB global MatrixC global Dimension global _real global _imag global MaxRndVal global Elapsed global ParallelElapsed # Arugments parser = argparse.ArgumentParser() parser.add_argument("-F", type=complex, nargs="?", default=Dimension) parser.add_argument("-G", type=complex, nargs="?", default=Dimension) parser.add_argument("-H", type=complex, nargs="?", default=Dimension) args = vars(parser.parse_args()) # Prepare Arugments f = args["F"] g = args["G"] h = args["H"] while True: Dimension = int(input("\n Enter Dimension (minimum 4): ")) if (Dimension >= 4): break print("\n Invalid dimension. Please re-enter (minimum 4).") # set the dimensions MatrixA = set_dimension(Dimension) MatrixB = set_dimension(Dimension) MatrixC = set_dimension(Dimension) while True: _real = int(input("\n Enter Random Maximum Real Value (minimum 10): ")) if (_real >= 10): break print("\n Invalid random maximum value. Please re-enter (minimum 10).") while True: _imag = int(input("\n Enter Random Maximum Imaginary Value (minimum 10): ")) if (_imag >= 10): break print("\n Invalid random maximum imaginary value. Please re-enter (minimum 10).") MaxRndVal = complex(_real, _imag) A = set_random_value(MatrixA, Dimension, MaxRndVal) B = set_random_value(MatrixA, Dimension, MaxRndVal) C = set_random_value(MatrixC, Dimension, 0) # Display First Matrix Multiply Processes - DaCe print("\n DaCe - MapReduce Process 0...") # display matrix print("\n Display Matrix A - DaCe") print(A) print("\n Display Matrix B - DaCe") print(B) ticmap = time.time() # matrix non-parallel multiplication - DaCe using gemm method print("\n Starting DaCe MapReduce Process 0: matrix multiplicationsdfg.optimize() - DaCe using map reduce...") matmul_Map_Final(A, B, C) tocmap = time.time() time_takenmap = tocmap - ticmap # time in s # Apply Transformations sdfg = matmul_Map_Final.to_sdfg() sdfg.apply_strict_transformations() sdfg.apply_transformations([MapFusion, MapWCRFusion, StateFusion]) sdfg.apply_transformations_repeated([MapFusion, MapWCRFusion, StateFusion]) # Feed Symbols sdfg(A=A, B=B, C=C, F=f, G=g, H=h) # Enumerating Matches for xform in Optimizer(sdfg).get_pattern_matches(patterns=[MapTiling]): print("Match:", xform.print_match(sdfg)) # Construct subgraph pattern (MapExit -> AccessNode -> MapEntry) pattern = sdutil.node_path_graph(dace.nodes.MapExit, dace.nodes.AccessNode, dace.nodes.MapEntry) # Loop over matches for subgraph in enumerate_matches(sdfg, pattern): print("Match found in state", subgraph.graph.label, ". Nodes:", subgraph.nodes()) # Interactive Optimization sdfg.optimize() # Display non-parallel multiplication - DaCe elapsed time print("\n Time taken - DaCe MapReduce x1 on CPU - Serial (in ms) = {}".format(time_takenmap * 1000)) # Display matrix multiplication elapsed time print("\n Matrix multiplication DACE MapReduce - elapsed time: {}".format(time_takenmap), "s") # display result matrix print("\n Display Result Matrix C - DaCe") print(C) # set random value in the matrix MatrixA = set_random_value(MatrixA, Dimension, MaxRndVal) MatrixB = set_random_value(MatrixB, Dimension, MaxRndVal) MatrixC = set_random_value(MatrixC, Dimension, 0) # because of result matrix must be zero # Display Second Matrix Multiply Processes - non-DaCe print("\n Non-DaCe Matrix Multiplication Process 1 and 2 Review....") # display matrix print("\n Display Matrix A") print(MatrixA) print("\n Display Matrix B") print(MatrixB) # matrix non-parallel multiplication print("\n Starting Process 1: non-parallel matrix multiplication ...") Elapsed = matrix_multiplication(Dimension) # Display non-parallel multiplication elapsed time print("\n Non-parallel multiplication elapsed time: ", Elapsed, "ms") # matrix parallel multiplication print("\n Starting Process 2: parallel matrix multiplication...") ParallelElapsed = matrix_parallel_multiplication(Dimension) # Display parallel multiplication elapsed time print("\n Parallel multiplication elapsed time: ", ParallelElapsed, "ms") # display result matrix print("\n Display Result Matrix C") print(MatrixC) # difference of two process print("\n Difference of non-DACE process 1 and 2 is: ", (Elapsed * 1000) - (ParallelElapsed * 1000), "ms") # difference of two process print("\n Difference of non-DACE process 1 and 2 is: ", (Elapsed) - (ParallelElapsed), "s") expected = MatrixA @ MatrixB diff = np.linalg.norm(MatrixC - expected) print('\n Difference:', diff) # exit(0 if diff <= 1e-5 else 1) assert diff < 1e-5 print("\n ==== Program end ==== \n")