STEllAR-GROUP / phylanx

An Asynchronous Distributed C++ Array Processing Toolkit
Boost Software License 1.0
75 stars 76 forks source link

Add support for `time` primitive in PhySL #1211

Closed taless474 closed 4 years ago

taless474 commented 4 years ago

Having the following code:

#include <phylanx/phylanx.hpp>

#include <hpx/hpx_init.hpp>
#include <hpx/include/lcos.hpp>
#include <hpx/include/util.hpp>
#include <hpx/modules/testing.hpp>

#include <cstdint>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

///////////////////////////////////////////////////////////////////////////////
char const* const conv1d_code = R"(block(
    define(conv,
        block(
            define(array,
                random_d(8,10,2),
            define(kernel,
                random(list(4, 2, 100))),
            conv1d_d(array, kernel)
        )
    ),
    conv
))";

////////////////////////////////////////////////////////////////////////////////
int hpx_main(int argc, char* argv[])
{
    using namespace phylanx::execution_tree;

    // compile the given code
    compiler::function_list snippets;
    auto const& compiled_code = compile("conv", conv1d_code, snippets);
    auto conv = compiled_code.run();

    std::cout << "Having "
        << hpx::get_num_localities(hpx::launch::sync)
        << " localities:\n";

    hpx::util::high_resolution_timer t;

    auto result = conv();
    auto elapsed = t.elapsed();

    std::cout << "Result of conv1d_d for the given csv file and the kernel is calculated in: " 
                   << elapsed << " seconds" << std::endl;

    return hpx::finalize();
}

int main(int argc, char* argv[])
{
    std::vector<std::string> cfg = {"hpx.run_hpx_main!=1"};

    return hpx::init(argc, argv, cfg);
}

the elapsed time contains the execution time of 3 primitives: random_d, random and conv1d_d. It would be really useful to have a primitive that enables us to separate these measurements. Having able to use hpx::util::high_resolution_timer in physl can be a solution.

hkaiser commented 4 years ago

@taless474 I'd suggest to add something like:

char const* const conv1d_code = R"(block(
    define(conv,
        block(
            define(array,
                random_d(8,10,2),
            define(kernel,
                random(list(4, 2, 100))),
            timer(
                conv1d_d(array, kernel),
                lambda(time, cout(time))
        )
    ),
    conv
))";

i.e. a primitive that times the execution of its first argument and passes the collected time to the function that is given as the second argument.