Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kordejong committed Dec 11, 2023
1 parent 7c590be commit 0a14fe0
Show file tree
Hide file tree
Showing 18 changed files with 575 additions and 133 deletions.
18 changes: 17 additions & 1 deletion source/framework/algorithm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,21 @@ block()
set(counter "0")

foreach(Policies IN LISTS LUE_FRAMEWORK_POLICIES)
math(EXPR count "${count} + 1")

# Instantiate highest_n
set(output_pathname "${CMAKE_CURRENT_BINARY_DIR}/${offset}/highest_n-${count}.cpp")

generate_template_instantiation(
INPUT_PATHNAME
"${CMAKE_CURRENT_SOURCE_DIR}/${offset}/highest_n.cpp.in"
OUTPUT_PATHNAME
"${output_pathname}"
DICTIONARY
'{"name":"${name}","Policies":"${Policies}","OutputElement":"${LUE_FRAMEWORK_BOOLEAN_ELEMENT}"}'
)
list(APPEND generated_source_files "${output_pathname}")

foreach(InputElement IN LISTS LUE_FRAMEWORK_ELEMENTS)
math(EXPR count "${count} + 1")
string(REPLACE "::" "_" name ${InputElement})
Expand All @@ -1498,7 +1513,7 @@ block()
)
list(APPEND generated_source_files "${output_pathname}")

# Instantiate highest_n
# Instantiate highest_n (global)
set(output_pathname "${CMAKE_CURRENT_BINARY_DIR}/${offset}/highest_n-${count}.cpp")

generate_template_instantiation(
Expand Down Expand Up @@ -1526,6 +1541,7 @@ block()
)
list(APPEND generated_source_files "${output_pathname}")

# Instantiate highest_n (zonal)
set(output_pathname "${CMAKE_CURRENT_BINARY_DIR}/${offset}/highest_n-${count}.cpp")

generate_template_instantiation(
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ namespace lue {

template<typename Policies, Rank rank>
PartitionedArray<policy::OutputElementT<Policies>, rank> highest_n(
Policies const& policies, SerialRoute<rank> const& route, Count const nr_cells);
Policies const& policies, SerialRoute<rank> const& route, Count const max_nr_cells);

template<typename Policies, typename ZoneElement, typename InputElement, Rank rank>
PartitionedArray<policy::OutputElementT<Policies>, rank> highest_n(
Policies const& policies,
PartitionedArray<ZoneElement, rank> const& region,
PartitionedArray<InputElement, rank> const& array,
Count const nr_cells);
Count const max_nr_cells);

template<typename Policies, typename InputElement, Rank rank>
PartitionedArray<policy::OutputElementT<Policies>, rank> highest_n(
Policies const& policies, PartitionedArray<InputElement, rank> const& array, Count const nr_cells);
Policies const& policies,
PartitionedArray<InputElement, rank> const& array,
Count const max_nr_cells);

} // namespace lue
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,36 @@ namespace lue {

namespace value_policies {

template<typename OutputElement, typename InputElement, Rank rank>
template<typename OutputElement, Rank rank>
PartitionedArray<OutputElement, rank> highest_n(
SerialRoute<rank> const& route,
PartitionedArray<InputElement, rank> const& array,
Count const nr_cells)
SerialRoute<rank> const& route, Count const max_nr_cells)
{
using Policies = policy::highest_n::DefaultValuePolicies<OutputElement, InputElement>;
using Policies = policy::highest_n::DefaultValuePolicies<OutputElement>;

return highest_n(Policies{}, route, array, nr_cells);
return highest_n(Policies{}, route, max_nr_cells);
}


template<typename OutputElement, typename ZoneElement, typename InputElement, Rank rank>
PartitionedArray<OutputElement, rank> highest_n(
PartitionedArray<ZoneElement, rank> const& zone,
PartitionedArray<InputElement, rank> const& array,
Count const nr_cells)
Count const max_nr_cells)
{
using Policies =
policy::highest_n::DefaultValuePolicies<OutputElement, ZoneElement, InputElement>;

return highest_n(Policies{}, zone, array, nr_cells);
return highest_n(Policies{}, zone, array, max_nr_cells);
}


template<typename OutputElement, typename InputElement, Rank rank>
PartitionedArray<OutputElement, rank> highest_n(
PartitionedArray<InputElement, rank> const& array, Count const nr_cells)
PartitionedArray<InputElement, rank> const& array, Count const max_nr_cells)
{
using Policies = policy::highest_n::DefaultValuePolicies<OutputElement, InputElement>;

return highest_n(Policies{}, array, nr_cells);
return highest_n(Policies{}, array, max_nr_cells);
}

} // namespace value_policies
Expand Down
18 changes: 14 additions & 4 deletions source/framework/algorithm/src/routing_operation/highest_n.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,38 @@
2,
{{ OutputElement }}_{{ ZoneElement }}_{{ InputElement }}
);
{% else %}
{% elif InputElement %}
LUE_REGISTER_HIGHEST_N_ACTIONS(
ESC(lue::policy::highest_n::{{ Policies }}<{{ OutputElement }}, {{ InputElement }}>),
2,
{{ OutputElement }}_{{ InputElement }}
);
{% else %}
LUE_REGISTER_HIGHEST_N_ACTIONS(
ESC(lue::policy::highest_n::{{ Policies }}<{{ OutputElement }}>),
2,
{{ OutputElement }}
);
{% endif %}


namespace lue {

{% if ZoneElement %}
LUE_INSTANTIATE_HIGHEST_N_ZONE(
LUE_INSTANTIATE_HIGHEST_N_ZONAL(
ESC(policy::highest_n::{{ Policies }}<{{ OutputElement }}, {{ ZoneElement }}, {{ InputElement }}>),
{{ ZoneElement }},
{{ InputElement }}
);
{% else %}
LUE_INSTANTIATE_HIGHEST_N(
{% elif InputElement %}
LUE_INSTANTIATE_HIGHEST_N_GLOBAL(
ESC(policy::highest_n::{{ Policies }}<{{ OutputElement }}, {{ InputElement }}>),
{{ InputElement }}
);
{% else %}
LUE_INSTANTIATE_HIGHEST_N(
ESC(policy::highest_n::{{ Policies }}<{{ OutputElement }}>)
);
{% endif %}

} // namespace lue
12 changes: 6 additions & 6 deletions source/framework/algorithm/test/highest_n_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ BOOST_AUTO_TEST_CASE(random_input)
lue::Count const max{500};
std::uniform_int_distribution<lue::Count> distribution(min, max);

return Shape{100, 100};
// return Shape{100, 100};

return Shape{
distribution(random_number_engine),
Expand All @@ -516,11 +516,11 @@ BOOST_AUTO_TEST_CASE(random_input)
}();
Shape const partition_shape = [&]()
{
lue::Count const min{90};
lue::Count const max{100};
lue::Count const min{40};
lue::Count const max{50};
std::uniform_int_distribution<lue::Count> distribution(min, max);

return Shape{10, 10};
// return Shape{10, 10};

return Shape{
distribution(random_number_engine),
Expand All @@ -533,7 +533,7 @@ BOOST_AUTO_TEST_CASE(random_input)
lue::Count const max{10};
std::uniform_int_distribution<lue::Count> distribution(min, max);

return lue::Count{100};
// return lue::Count{100};

return distribution(random_number_engine);
}();
Expand All @@ -544,7 +544,7 @@ BOOST_AUTO_TEST_CASE(random_input)
lue::Count const max{lue::nr_elements(array_shape)};
std::uniform_int_distribution<lue::Count> distribution(min, max);

return lue::Count{10000};
// return lue::Count{10000};

return distribution(random_number_engine);
}();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ namespace lue::server {
{
for (auto const& fragment : fragments)
{
for (auto const& cell_idx : fragment.cell_idxs())
for ([[maybe_unused]] auto const& cell_idx : fragment.cell_idxs())
{
lue_hpx_assert(cell_idx >= 0);
lue_hpx_assert(cell_idx < nr_elements(_shape));
Expand Down
4 changes: 4 additions & 0 deletions source/framework/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ add_library(lue_py_framework SHARED
src/algorithm/local_operation/unique_id.cpp

src/algorithm/routing_operation.cpp
src/algorithm/routing_operation/decreasing_order.cpp
src/algorithm/routing_operation/highest_n.cpp
src/algorithm/routing_operation/kinematic_wave.cpp

src/algorithm/zonal_operation.cpp
Expand Down Expand Up @@ -144,6 +146,8 @@ add_library(lue_py_framework SHARED
src/numpy/from_numpy.cpp
src/numpy/to_numpy.cpp

src/partitioned_route/serial_route.cpp

src/python_extension.cpp
src/submodule.cpp
)
Expand Down
4 changes: 4 additions & 0 deletions source/framework/python/src/algorithm/routing_operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@

namespace lue::framework {

void bind_decreasing_order(pybind11::module& module);
void bind_highest_n(pybind11::module& module);
void bind_kinematic_wave(pybind11::module& module);


void bind_routing_operations(pybind11::module& module)
{
bind_decreasing_order(module);
bind_highest_n(module);
bind_kinematic_wave(module);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "lue/framework/algorithm/value_policies/decreasing_order.hpp"
#include <pybind11/pybind11.h>


namespace lue::framework {

namespace detail {

template<typename ValueElement>
void bind_decreasing_order(pybind11::module& module)
{
module.def("decreasing_order", lue::value_policies::decreasing_order<ValueElement, 2>);
}


template<typename ZoneElement, typename ValueElement>
void bind_decreasing_order(pybind11::module& module)
{
module.def(
"decreasing_order", lue::value_policies::decreasing_order<ZoneElement, ValueElement, 2>);
}

} // namespace detail

void bind_decreasing_order(pybind11::module& module)
{
// Global
detail::bind_decreasing_order<std::uint8_t>(module);
detail::bind_decreasing_order<std::int32_t>(module);
detail::bind_decreasing_order<std::int64_t>(module);
detail::bind_decreasing_order<std::uint32_t>(module);
detail::bind_decreasing_order<std::uint64_t>(module);
detail::bind_decreasing_order<float>(module);
detail::bind_decreasing_order<double>(module);

// Zonal
detail::bind_decreasing_order<std::uint8_t, std::uint8_t>(module);
detail::bind_decreasing_order<std::int32_t, std::uint8_t>(module);
detail::bind_decreasing_order<std::int64_t, std::uint8_t>(module);
detail::bind_decreasing_order<std::uint32_t, std::uint8_t>(module);
detail::bind_decreasing_order<std::uint64_t, std::uint8_t>(module);

detail::bind_decreasing_order<std::uint8_t, std::int32_t>(module);
detail::bind_decreasing_order<std::int32_t, std::int32_t>(module);
detail::bind_decreasing_order<std::int64_t, std::int32_t>(module);
detail::bind_decreasing_order<std::uint32_t, std::int32_t>(module);
detail::bind_decreasing_order<std::uint64_t, std::int32_t>(module);

detail::bind_decreasing_order<std::uint8_t, std::int64_t>(module);
detail::bind_decreasing_order<std::int32_t, std::int64_t>(module);
detail::bind_decreasing_order<std::int64_t, std::int64_t>(module);
detail::bind_decreasing_order<std::uint32_t, std::int64_t>(module);
detail::bind_decreasing_order<std::uint64_t, std::int64_t>(module);

detail::bind_decreasing_order<std::uint8_t, std::uint32_t>(module);
detail::bind_decreasing_order<std::int32_t, std::uint32_t>(module);
detail::bind_decreasing_order<std::int64_t, std::uint32_t>(module);
detail::bind_decreasing_order<std::uint32_t, std::uint32_t>(module);
detail::bind_decreasing_order<std::uint64_t, std::uint32_t>(module);

detail::bind_decreasing_order<std::uint8_t, std::uint64_t>(module);
detail::bind_decreasing_order<std::int32_t, std::uint64_t>(module);
detail::bind_decreasing_order<std::int64_t, std::uint64_t>(module);
detail::bind_decreasing_order<std::uint32_t, std::uint64_t>(module);
detail::bind_decreasing_order<std::uint64_t, std::uint64_t>(module);

detail::bind_decreasing_order<std::uint8_t, float>(module);
detail::bind_decreasing_order<std::int32_t, float>(module);
detail::bind_decreasing_order<std::int64_t, float>(module);
detail::bind_decreasing_order<std::uint32_t, float>(module);
detail::bind_decreasing_order<std::uint64_t, float>(module);

detail::bind_decreasing_order<std::uint8_t, double>(module);
detail::bind_decreasing_order<std::int32_t, double>(module);
detail::bind_decreasing_order<std::int64_t, double>(module);
detail::bind_decreasing_order<std::uint32_t, double>(module);
detail::bind_decreasing_order<std::uint64_t, double>(module);
}

} // namespace lue::framework
Loading

0 comments on commit 0a14fe0

Please sign in to comment.