Skip to content

Instantly share code, notes, and snippets.

@taless474
Last active April 14, 2020 00:46
Show Gist options
  • Save taless474/0621f08e03d13e16d7bad1dd655fb155 to your computer and use it in GitHub Desktop.
Save taless474/0621f08e03d13e16d7bad1dd655fb155 to your computer and use it in GitHub Desktop.
// Copyright (c) 2020 Bita Hasheminezhad
// Copyright (c) 2020 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <phylanx/phylanx.hpp>
#include <hpx/hpx_init.hpp>
#include <hpx/include/lcos.hpp>
#include <hpx/testing.hpp>
#include <array>
#include <cstdint>
#include <string>
#include <utility>
#include <vector>
#include <iostream>
#include <blaze/Math.h>
#include <blaze_tensor/Math.h>
///////////////////////////////////////////////////////////////////////////////
phylanx::execution_tree::primitive_argument_type compile_and_run(
std::string const& name, std::string const& codestr)
{
phylanx::execution_tree::compiler::function_list snippets;
phylanx::execution_tree::compiler::environment env =
phylanx::execution_tree::compiler::default_environment();
auto const& code =
phylanx::execution_tree::compile(name, codestr, snippets, env);
return code.run().arg_;
}
void test_retile_d_operation(std::string const& name, std::string const& code,
std::string const& expected_str)
{
phylanx::execution_tree::primitive_argument_type result =
compile_and_run(name, code);
phylanx::execution_tree::primitive_argument_type comparison =
compile_and_run(name, expected_str);
//std::cout << "result:" << result << "\n";
//std::cout << "comparison:" << comparison << "\n";
HPX_TEST_EQ(result, comparison);
}
///////////////////////////////////////////////////////////////////////////////
//void test_retile_6loc_2d_0()
//{
// if (hpx::get_locality_id() == 0)
// {
// test_retile_d_operation("test_retile_6loc2d_0", R"(
// retile_d(
// annotate_d([[-5, -6], [15, 16], [-15, -16]],
// "tiled_array_2d_0",
// list("tile", list("columns", 4, 6), list("rows", 1, 4))
// ),
// list("tile", list("columns", 0, 2), list("rows", 0, 2))
// )
// )", R"(
// annotate_d([[1, 2], [-1, -2]], "tiled_array_2d_0_retiled/1",
// list("args",
// list("locality", 0, 6),
// list("tile", list("columns", 0, 2), list("rows", 0, 2))))
// )");
// }
// else if (hpx::get_locality_id() == 1)
// {
// test_retile_d_operation("test_retile_6loc2d_0", R"(
// retile_d(
// annotate_d([[1]], "tiled_array_2d_0",
// list("tile", list("columns", 0, 1), list("rows", 0, 1))
// ),
// list("tile", list("columns", 2, 4), list("rows", 0, 2))
// )
// )", R"(
// annotate_d([[3, 4], [-3, -4]], "tiled_array_2d_0_retiled/1",
// list("args",
// list("locality", 1, 6),
// list("tile", list("columns", 2, 4), list("rows", 0, 2))))
// )");
// }
// else if (hpx::get_locality_id() == 2)
// {
// test_retile_d_operation("test_retile_6loc2d_0", R"(
// retile_d(
// annotate_d([[2, 3, 4]], "tiled_array_2d_0",
// list("tile", list("columns", 1, 4), list("rows", 0, 1))
// ),
// list("tile", list("columns", 4, 6), list("rows", 0, 2))
// )
// )", R"(
// annotate_d([[5, 6], [-5, -6]], "tiled_array_2d_0_retiled/1",
// list("args",
// list("locality", 2, 6),
// list("tile", list("columns", 4, 6), list("rows", 0, 2))))
// )");
// }
// else if (hpx::get_locality_id() == 3)
// {
// test_retile_d_operation("test_retile_6loc2d_0", R"(
// retile_d(
// annotate_d([[5, 6]], "tiled_array_2d_0",
// list("tile", list("columns", 4, 6), list("rows", 0, 1))
// ),
// list("tile", list("columns", 0, 2), list("rows", 2, 4))
// )
// )", R"(
// annotate_d([[11, 12], [-11, -12]], "tiled_array_2d_0_retiled/1",
// list("args",
// list("locality", 3, 6),
// list("tile", list("columns", 0, 2), list("rows", 2, 4))))
// )");
// }
// else if (hpx::get_locality_id() == 4)
// {
// test_retile_d_operation("test_retile_6loc2d_0", R"(
// retile_d(
// annotate_d([[-1], [11], [-11]], "tiled_array_2d_0",
// list("tile", list("columns", 0, 1), list("rows", 1, 4))
// ),
// list("tile", list("columns", 2, 4), list("rows", 2, 4))
// )
// )", R"(
// annotate_d([[13, 14], [-13, -14]], "tiled_array_2d_0_retiled/1",
// list("args",
// list("locality", 4, 6),
// list("tile", list("columns", 2, 4), list("rows", 2, 4))))
// )");
// }
// else if (hpx::get_locality_id() == 5)
// {
// test_retile_d_operation("test_retile_6loc2d_0", R"(
// retile_d(
// annotate_d([[-2, -3, -4], [12, 13, 14], [-12, -13, -14]],
// "tiled_array_2d_0",
// list("tile", list("columns", 1, 4), list("rows", 1, 4))
// ),
// list("tile", list("columns", 4, 6), list("rows", 2, 4))
// )
// )", R"(
// annotate_d([[15, 16], [-15, -16]], "tiled_array_2d_0_retiled/1",
// list("args",
// list("locality", 5, 6),
// list("tile", list("columns", 4, 6), list("rows", 2, 4))))
// )");
// }
//}
void test_retile_6loc_2d_0()
{
if (hpx::get_locality_id() == 0)
{
test_retile_d_operation("test_retile_6loc2d_0", R"(
retile_d(
annotate_d([[1]],
"tiled_array_2d_0",
list("tile", list("columns", 0, 1), list("rows", 0, 1))
),
list("tile", list("columns", 0, 2), list("rows", 0, 2))
)
)", R"(
annotate_d([[1, 2], [-1, -2]], "tiled_array_2d_0_retiled/1",
list("args",
list("locality", 0, 6),
list("tile", list("columns", 0, 2), list("rows", 0, 2))))
)");
}
else if (hpx::get_locality_id() == 1)
{
test_retile_d_operation("test_retile_6loc2d_0", R"(
retile_d(
annotate_d([[2, 3, 4]], "tiled_array_2d_0",
list("tile", list("columns", 1, 4), list("rows", 0, 1))
),
list("tile", list("columns", 2, 4), list("rows", 0, 2))
)
)", R"(
annotate_d([[3, 4], [-3, -4]], "tiled_array_2d_0_retiled/1",
list("args",
list("locality", 1, 6),
list("tile", list("columns", 2, 4), list("rows", 0, 2))))
)");
}
else if (hpx::get_locality_id() == 2)
{
test_retile_d_operation("test_retile_6loc2d_0", R"(
retile_d(
annotate_d([[5, 6]], "tiled_array_2d_0",
list("tile", list("columns", 4, 6), list("rows", 0, 1))
),
list("tile", list("columns", 4, 6), list("rows", 0, 2))
)
)", R"(
annotate_d([[5, 6], [-5, -6]], "tiled_array_2d_0_retiled/1",
list("args",
list("locality", 2, 6),
list("tile", list("columns", 4, 6), list("rows", 0, 2))))
)");
}
else if (hpx::get_locality_id() == 3)
{
test_retile_d_operation("test_retile_6loc2d_0", R"(
retile_d(
annotate_d([[-1], [11], [-11]], "tiled_array_2d_0",
list("tile", list("columns", 0, 1), list("rows", 1, 4))
),
list("tile", list("columns", 0, 2), list("rows", 2, 4))
)
)", R"(
annotate_d([[11, 12], [-11, -12]], "tiled_array_2d_0_retiled/1",
list("args",
list("locality", 3, 6),
list("tile", list("columns", 0, 2), list("rows", 2, 4))))
)");
}
else if (hpx::get_locality_id() == 4)
{
test_retile_d_operation("test_retile_6loc2d_0", R"(
retile_d(
annotate_d([[-2, -3, -4], [12, 13, 14], [-12, -13, -14]],
"tiled_array_2d_0",
list("tile", list("columns", 1, 4), list("rows", 1, 4))
),
list("tile", list("columns", 2, 4), list("rows", 2, 4))
)
)", R"(
annotate_d([[13, 14], [-13, -14]], "tiled_array_2d_0_retiled/1",
list("args",
list("locality", 4, 6),
list("tile", list("columns", 2, 4), list("rows", 2, 4))))
)");
}
else if (hpx::get_locality_id() == 5)
{
test_retile_d_operation("test_retile_6loc2d_0", R"(
retile_d(
annotate_d([[-5, -6], [15, 16], [-15, -16]],
"tiled_array_2d_0",
list("tile", list("columns", 4, 6), list("rows", 1, 4))
),
list("tile", list("columns", 4, 6), list("rows", 2, 4))
)
)", R"(
annotate_d([[15, 16], [-15, -16]], "tiled_array_2d_0_retiled/1",
list("args",
list("locality", 5, 6),
list("tile", list("columns", 4, 6), list("rows", 2, 4))))
)");
}
}
///////////////////////////////////////////////////////////////////////////////
int hpx_main(int argc, char* argv[])
{
test_retile_6loc_2d_0();
hpx::finalize();
return hpx::util::report_errors();
}
int main(int argc, char* argv[])
{
std::vector<std::string> cfg = {
"hpx.run_hpx_main!=1"
};
return hpx::init(argc, argv, cfg);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment