Exemplo n.º 1
0
    /// <summary> Vector addition on DFE </summary>
    /// <param name = "size"> Size of arrays </param>
    /// <param name = "firstVector"> First vector </param>
    /// <param name = "secondVector"> Second vector </param>
    /// <param name = "scalar"> Scalar parameter </param>
    /// <returns> Data output </returns>
    public static List <int> VectorAdditionDfe(int size, List <int> firstVector, List <int> secondVector, int scalar)
    {
        Stopwatch sw = new Stopwatch();

        sw.Start();

        // Make socket
        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 VectorAdditionService.Client(protocol);

        sw.Stop();
        Console.WriteLine("Creating a client:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

        List <int> dataOut = new List <int>();

        try
        {
            // 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_x = client.malloc_int32_t(size);
            client.send_data_int32_t(address_x, firstVector);

            var address_y = client.malloc_int32_t(size);
            client.send_data_int32_t(address_y, secondVector);
            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_out = client.malloc_float(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.VectorAddition_writeLMem(0, size * 4, address_x);
            sw.Stop();
            Console.WriteLine("Writing to LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Action default
            sw.Reset();
            sw.Start();
            client.VectorAddition(scalar, size, address_y, address_out);
            sw.Stop();
            Console.WriteLine("Vector addition time:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Get output stream from server
            sw.Reset();
            sw.Start();
            dataOut = client.receive_data_int32_t(address_out, 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_x);
            client.free(address_y);
            client.free(address_out);
            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(dataOut);
    }
Exemplo n.º 2
0
    /// <summary> Vector addition on DFE </summary>
    /// <param name = "size"> Size of arrays </param>
    /// <param name = "firstVector"> First vector </param>
    /// <param name = "secondVector"> Second vector </param>
    /// <param name = "scalar"> Scalar parameter </param>
    /// <returns> Data output </returns>
    public static List<int> VectorAdditionDfe(int size, List<int> firstVector, List<int> secondVector, int scalar)
    {
        Stopwatch sw = new Stopwatch();
        sw.Start();

        // Make socket
        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 VectorAdditionService.Client(protocol);

        sw.Stop();
        Console.WriteLine("Creating a client:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

        List<int> dataOut = new List<int>();

        try
        {
            // 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.VectorAddition_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_x = client.malloc_int32_t(size);
            client.send_data_int32_t(address_x, firstVector);

            var address_y = client.malloc_int32_t(size);
            client.send_data_int32_t(address_y, secondVector);
            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_out = client.malloc_float(size);
            sw.Stop();
            Console.WriteLine("Allocating memory for output stream on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Action writeLMem
            sw.Reset();
            sw.Start();
            var act = client.max_actions_init(maxfile, "writeLMem");
            client.max_set_param_uint64t(act, "address", 0);
            client.max_set_param_uint64t(act, "nbytes", size * 4);
            client.max_queue_input(act, "cpu_to_lmem", address_x, size * 4);
            client.max_run(engine, act);
            sw.Stop();
            Console.WriteLine("Writing to LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Action default
            sw.Reset();
            sw.Start();
            act = client.max_actions_init(maxfile, "default");
            client.max_set_param_uint64t(act, "N", size);
            client.max_set_param_uint64t(act, "A", scalar);
            client.max_queue_input(act, "y", address_y, size * 4);
            client.max_queue_output(act, "s", address_out, size * 4);
            client.max_run(engine, act);
            sw.Stop();
            Console.WriteLine("Vector addition time:\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();
            dataOut = client.receive_data_int32_t(address_out, 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_x);
            client.free(address_y);
            client.free(address_out);
            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.VectorAddition_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 dataOut;
    }
    /// <summary> Vector addition on DFE </summary>
    /// <param name = "size"> Size of arrays </param>
    /// <param name = "firstVector"> First vector </param>
    /// <param name = "secondVector"> Second vector </param>
    /// <param name = "scalar"> Scalar parameter </param>
    /// <returns> Data output </returns>
    public static List <int> VectorAdditionDfe(int size, List <int> firstVector, List <int> secondVector, int scalar)
    {
        Stopwatch sw = new Stopwatch();

        sw.Start();

        // Make socket
        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 VectorAdditionService.Client(protocol);

        sw.Stop();
        Console.WriteLine("Creating a client:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

        List <int> dataOut = new List <int>();

        try
        {
            // 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.VectorAddition_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_x = client.malloc_int32_t(size);
            client.send_data_int32_t(address_x, firstVector);

            var address_y = client.malloc_int32_t(size);
            client.send_data_int32_t(address_y, secondVector);
            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_out = client.malloc_float(size);
            sw.Stop();
            Console.WriteLine("Allocating memory for output stream on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Action writeLMem
            sw.Reset();
            sw.Start();
            var act = client.max_actions_init(maxfile, "writeLMem");
            client.max_set_param_uint64t(act, "address", 0);
            client.max_set_param_uint64t(act, "nbytes", size * 4);
            client.max_queue_input(act, "cpu_to_lmem", address_x, size * 4);
            client.max_run(engine, act);
            sw.Stop();
            Console.WriteLine("Writing to LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Action default
            sw.Reset();
            sw.Start();
            act = client.max_actions_init(maxfile, "default");
            client.max_set_param_uint64t(act, "N", size);
            client.max_set_param_uint64t(act, "A", scalar);
            client.max_queue_input(act, "y", address_y, size * 4);
            client.max_queue_output(act, "s", address_out, size * 4);
            client.max_run(engine, act);
            sw.Stop();
            Console.WriteLine("Vector addition time:\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();
            dataOut = client.receive_data_int32_t(address_out, 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_x);
            client.free(address_y);
            client.free(address_out);
            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.VectorAddition_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(dataOut);
    }
Exemplo n.º 4
0
    /// <summary> Vector addition on DFE </summary>
    /// <param name = "size"> Size of arrays </param>
    /// <param name = "firstVector"> First vector </param>
    /// <param name = "secondVector"> Second vector </param>
    /// <param name = "scalar"> Scalar parameter </param>
    /// <returns> Data output </returns>
    public static List<int> VectorAdditionDfe(int size, List<int> firstVector, List<int> secondVector, int scalar)
    {
        Stopwatch sw = new Stopwatch();
        sw.Start();

        // Make socket
        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 VectorAdditionService.Client(protocol);

        sw.Stop();
        Console.WriteLine("Creating a client:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

        List<int> dataOut = new List<int>();

        try
        {
            // 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_x = client.malloc_int32_t(size);
            client.send_data_int32_t(address_x, firstVector);

            var address_y = client.malloc_int32_t(size);
            client.send_data_int32_t(address_y, secondVector);
            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_out = client.malloc_float(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.VectorAddition_writeLMem(0, size * 4, address_x);
            sw.Stop();
            Console.WriteLine("Writing to LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Action default
            sw.Reset();
            sw.Start();
            client.VectorAddition(scalar, size, address_y, address_out);
            sw.Stop();
            Console.WriteLine("Vector addition time:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Get output stream from server
            sw.Reset();
            sw.Start();
            dataOut = client.receive_data_int32_t(address_out, 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_x);
            client.free(address_y);
            client.free(address_out);
            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 dataOut;
    }