/// <summary> LMemLoopback on DFE </summary> /// <param name = "size"> Size of arrays </param> /// <param name = "inA"> First array </param> /// <param name = "inB"> Second array </param> /// <returns> Data output </returns> public static List<int> LMemLoopbackDFE(int size, List<int> inA, List<int> inB) { Stopwatch sw = new Stopwatch(); List<int> outData = new List<int>(); int sizeBytes = size * 4; try { // Connect! var transport = new TSocket("localhost", 9090); var protocol = new TBinaryProtocol(transport); var client = new LMemLoopbackService.Client(protocol); transport.Open(); // Initialize maxfile sw.Reset(); sw.Start(); var maxfile = client.LMemLoopback_init(); sw.Stop(); Console.WriteLine("Initializing maxfile:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Load DFE sw.Reset(); sw.Start(); var engine = client.max_load(maxfile, "*"); sw.Stop(); Console.WriteLine("Loading DFE:\t\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Allocate and send input streams to server sw.Reset(); sw.Start(); var address_inA = client.malloc_int32_t(size); client.send_data_int32_t(address_inA, inA); var address_inB = client.malloc_int32_t(size); client.send_data_int32_t(address_inB, inB); sw.Stop(); Console.WriteLine("Sending input data:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Allocate memory for output stream on server sw.Reset(); sw.Start(); var address_outData = client.malloc_int32_t(size); sw.Stop(); Console.WriteLine("Allocating memory for output stream on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Writing to LMem sw.Reset(); sw.Start(); var actions = client.max_actions_init(maxfile, "writeLMem"); client.max_set_param_uint64t(actions, "address", 0); client.max_set_param_uint64t(actions, "nbytes", sizeBytes); client.max_queue_input(actions, "cpu_to_lmem", address_inA, sizeBytes); client.max_run(engine, actions); actions = client.max_actions_init(maxfile, "writeLMem"); client.max_set_param_uint64t(actions, "address", sizeBytes); client.max_set_param_uint64t(actions, "nbytes", sizeBytes); client.max_queue_input(actions, "cpu_to_lmem", address_inB, sizeBytes); client.max_run(engine, actions); sw.Stop(); Console.WriteLine("Writing to LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Action default sw.Reset(); sw.Start(); actions = client.max_actions_init(maxfile, "default"); client.max_set_param_uint64t(actions, "N", size); client.max_run(engine, actions); sw.Stop(); Console.WriteLine("LMemLoopback time:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Reading from LMem sw.Reset(); sw.Start(); actions = client.max_actions_init(maxfile, "readLMem"); client.max_set_param_uint64t(actions, "address", 2 * sizeBytes); client.max_set_param_uint64t(actions, "nbytes", sizeBytes); client.max_queue_output(actions, "lmem_to_cpu", address_outData, sizeBytes); client.max_run(engine, actions); client.free(actions); sw.Stop(); Console.WriteLine("Reading from LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Unload DFE sw.Reset(); sw.Start(); client.max_unload(engine); sw.Stop(); Console.WriteLine("Unloading DFE:\t\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Get output stream from server sw.Reset(); sw.Start(); outData = client.receive_data_int32_t(address_outData, size); sw.Stop(); Console.WriteLine("Getting output stream:\t(size = {0} bit)\t{1}s", size * 32, sw.Elapsed.TotalMilliseconds / 1000); // Free allocated memory for streams on server sw.Reset(); sw.Start(); client.free(address_inA); client.free(address_inB); client.free(address_outData); sw.Stop(); Console.WriteLine("Freeing allocated memory for streams on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Free allocated maxfile data sw.Reset(); sw.Start(); client.LMemLoopback_free(); sw.Stop(); Console.WriteLine("Freeing allocated maxfile data:\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Close! sw.Reset(); sw.Start(); transport.Close(); sw.Stop(); Console.WriteLine("Closing connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); } catch (SocketException e) { Console.WriteLine("Could not connect to the server: {0}.", e.Message); Environment.Exit(-1); } catch (Exception e) { Console.WriteLine("An error occured: {0}", e.Message); Environment.Exit(-1); } return outData; }
/// <summary> LMemLoopback on DFE </summary> /// <param name = "size"> Size of arrays </param> /// <param name = "inA"> First array </param> /// <param name = "inB"> Second array </param> /// <returns> Data output </returns> public static List<int> LMemLoopbackDFE(int size, List<int> inA, List<int> inB) { List<int> outData = new List<int>(); int sizeBytes = size * 4; Stopwatch sw = new Stopwatch(); try { // Make socket sw.Start(); var transport = new TSocket("localhost", 9090); // Wrap in a protocol var protocol = new TBinaryProtocol(transport); // Create a client to use the protocol encoder var client = new LMemLoopbackService.Client(protocol); sw.Stop(); Console.WriteLine("Creating a client:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Connect! sw.Reset(); sw.Start(); transport.Open(); sw.Stop(); Console.WriteLine("Opening connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Allocate and send input streams to server sw.Reset(); sw.Start(); var address_inA = client.malloc_int32_t(size); client.send_data_int32_t(address_inA, inA); var address_inB = client.malloc_int32_t(size); client.send_data_int32_t(address_inB, inB); sw.Stop(); Console.WriteLine("Sending input data:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Allocate memory for output stream on server sw.Reset(); sw.Start(); var address_outData = client.malloc_int32_t(size); sw.Stop(); Console.WriteLine("Allocating memory for output stream on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Writing to LMem sw.Reset(); sw.Start(); client.LMemLoopback_writeLMem(0, sizeBytes, address_inA); client.LMemLoopback_writeLMem(sizeBytes, sizeBytes, address_inB); sw.Stop(); Console.WriteLine("Writing to LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Action default sw.Reset(); sw.Start(); client.LMemLoopback(size); sw.Stop(); Console.WriteLine("LMemLoopback time:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Reading from LMem sw.Reset(); sw.Start(); client.LMemLoopback_readLMem(2 * sizeBytes, sizeBytes, address_outData); sw.Stop(); Console.WriteLine("Reading from LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Get output stream from server sw.Reset(); sw.Start(); outData = client.receive_data_int32_t(address_outData, size); sw.Stop(); Console.WriteLine("Getting output stream:\t(size = {0} bit)\t{1}s", size * 32, sw.Elapsed.TotalMilliseconds / 1000); // Free allocated memory for streams on server sw.Reset(); sw.Start(); client.free(address_inA); client.free(address_inB); client.free(address_outData); sw.Stop(); Console.WriteLine("Freeing allocated memory for streams on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Close! sw.Reset(); sw.Start(); transport.Close(); sw.Stop(); Console.WriteLine("Closing connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); } catch (SocketException e) { Console.WriteLine("Could not connect to the server: {0}.", e.Message); Environment.Exit(-1); } catch (Exception e) { Console.WriteLine("An error occured: {0}", e.Message); Environment.Exit(-1); } return outData; }
/// <summary> LMemLoopback on DFE </summary> /// <param name = "size"> Size of arrays </param> /// <param name = "inA"> First array </param> /// <param name = "inB"> Second array </param> /// <returns> Data output </returns> public static List <int> LMemLoopbackDFE(int size, List <int> inA, List <int> inB) { Stopwatch sw = new Stopwatch(); List <int> outData = new List <int>(); int sizeBytes = size * 4; try { // Make socket sw.Start(); var transport = new TSocket("localhost", 9090); // Wrap in a protocol var protocol = new TBinaryProtocol(transport); // Create a client to use the protocol encoder var client = new LMemLoopbackService.Client(protocol); sw.Stop(); Console.WriteLine("Creating a client:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Connect! sw.Reset(); sw.Start(); transport.Open(); sw.Stop(); Console.WriteLine("Opening connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Initialize maxfile sw.Reset(); sw.Start(); var maxfile = client.LMemLoopback_init(); sw.Stop(); Console.WriteLine("Initializing maxfile:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Load DFE sw.Reset(); sw.Start(); var engine = client.max_load(maxfile, "*"); sw.Stop(); Console.WriteLine("Loading DFE:\t\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Allocate and send input streams to server sw.Reset(); sw.Start(); var address_inA = client.malloc_int32_t(size); client.send_data_int32_t(address_inA, inA); var address_inB = client.malloc_int32_t(size); client.send_data_int32_t(address_inB, inB); sw.Stop(); Console.WriteLine("Sending input data:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Allocate memory for output stream on server sw.Reset(); sw.Start(); var address_outData = client.malloc_int32_t(size); sw.Stop(); Console.WriteLine("Allocating memory for output stream on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Writing to LMem sw.Reset(); sw.Start(); var actions_lmem_write = new LMemLoopback_writeLMem_actions_t_struct(); actions_lmem_write.Param_address = 0; actions_lmem_write.Param_nbytes = sizeBytes; actions_lmem_write.Instream_cpu_to_lmem = address_inA; var address_actions_lmem_write = client.send_LMemLoopback_writeLMem_actions_t(actions_lmem_write); client.LMemLoopback_writeLMem_run(engine, address_actions_lmem_write); actions_lmem_write.Param_address = sizeBytes; actions_lmem_write.Param_nbytes = sizeBytes; actions_lmem_write.Instream_cpu_to_lmem = address_inB; address_actions_lmem_write = client.send_LMemLoopback_writeLMem_actions_t(actions_lmem_write); client.LMemLoopback_writeLMem_run(engine, address_actions_lmem_write); client.free(address_actions_lmem_write); sw.Stop(); Console.WriteLine("Writing to LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Action default sw.Reset(); sw.Start(); var actions = new LMemLoopback_actions_t_struct(); actions.Param_N = size; var address_actions = client.send_LMemLoopback_actions_t(actions); client.LMemLoopback_run(engine, address_actions); client.free(address_actions); sw.Stop(); Console.WriteLine("LMemLoopback time:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Reading from LMem sw.Reset(); sw.Start(); var actions_lmem_read = new LMemLoopback_readLMem_actions_t_struct(); actions_lmem_read.Param_address = 2 * sizeBytes; actions_lmem_read.Param_nbytes = sizeBytes; actions_lmem_read.Outstream_lmem_to_cpu = address_outData; var address_actions_lmem_read = client.send_LMemLoopback_readLMem_actions_t(actions_lmem_read); client.LMemLoopback_readLMem_run(engine, address_actions_lmem_read); client.free(address_actions_lmem_read); sw.Stop(); Console.WriteLine("Reading from LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Unload DFE sw.Reset(); sw.Start(); client.max_unload(engine); sw.Stop(); Console.WriteLine("Unloading DFE:\t\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Get output stream from server sw.Reset(); sw.Start(); outData = client.receive_data_int32_t(address_outData, size); sw.Stop(); Console.WriteLine("Getting output stream:\t(size = {0} bit)\t{1}s", size * 32, sw.Elapsed.TotalMilliseconds / 1000); // Free allocated memory for streams on server sw.Reset(); sw.Start(); client.free(address_inA); client.free(address_inB); client.free(address_outData); sw.Stop(); Console.WriteLine("Freeing allocated memory for streams on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Free allocated maxfile data sw.Reset(); sw.Start(); client.LMemLoopback_free(); sw.Stop(); Console.WriteLine("Freeing allocated maxfile data:\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Close! sw.Reset(); sw.Start(); transport.Close(); sw.Stop(); Console.WriteLine("Closing connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); } catch (SocketException e) { Console.WriteLine("Could not connect to the server: {0}.", e.Message); Environment.Exit(-1); } catch (Exception e) { Console.WriteLine("An error occured: {0}", e.Message); Environment.Exit(-1); } return(outData); }
/// <summary> LMemLoopback on DFE </summary> /// <param name = "size"> Size of arrays </param> /// <param name = "inA"> First array </param> /// <param name = "inB"> Second array </param> /// <returns> Data output </returns> public static List <int> LMemLoopbackDFE(int size, List <int> inA, List <int> inB) { List <int> outData = new List <int>(); int sizeBytes = size * 4; Stopwatch sw = new Stopwatch(); try { // Make socket sw.Start(); var transport = new TSocket("localhost", 9090); // Wrap in a protocol var protocol = new TBinaryProtocol(transport); // Create a client to use the protocol encoder var client = new LMemLoopbackService.Client(protocol); sw.Stop(); Console.WriteLine("Creating a client:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Connect! sw.Reset(); sw.Start(); transport.Open(); sw.Stop(); Console.WriteLine("Opening connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Allocate and send input streams to server sw.Reset(); sw.Start(); var address_inA = client.malloc_int32_t(size); client.send_data_int32_t(address_inA, inA); var address_inB = client.malloc_int32_t(size); client.send_data_int32_t(address_inB, inB); sw.Stop(); Console.WriteLine("Sending input data:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Allocate memory for output stream on server sw.Reset(); sw.Start(); var address_outData = client.malloc_int32_t(size); sw.Stop(); Console.WriteLine("Allocating memory for output stream on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Writing to LMem sw.Reset(); sw.Start(); client.LMemLoopback_writeLMem(0, sizeBytes, address_inA); client.LMemLoopback_writeLMem(sizeBytes, sizeBytes, address_inB); sw.Stop(); Console.WriteLine("Writing to LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Action default sw.Reset(); sw.Start(); client.LMemLoopback(size); sw.Stop(); Console.WriteLine("LMemLoopback time:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Reading from LMem sw.Reset(); sw.Start(); client.LMemLoopback_readLMem(2 * sizeBytes, sizeBytes, address_outData); sw.Stop(); Console.WriteLine("Reading from LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Get output stream from server sw.Reset(); sw.Start(); outData = client.receive_data_int32_t(address_outData, size); sw.Stop(); Console.WriteLine("Getting output stream:\t(size = {0} bit)\t{1}s", size * 32, sw.Elapsed.TotalMilliseconds / 1000); // Free allocated memory for streams on server sw.Reset(); sw.Start(); client.free(address_inA); client.free(address_inB); client.free(address_outData); sw.Stop(); Console.WriteLine("Freeing allocated memory for streams on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); // Close! sw.Reset(); sw.Start(); transport.Close(); sw.Stop(); Console.WriteLine("Closing connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000); } catch (SocketException e) { Console.WriteLine("Could not connect to the server: {0}.", e.Message); Environment.Exit(-1); } catch (Exception e) { Console.WriteLine("An error occured: {0}", e.Message); Environment.Exit(-1); } return(outData); }