diff --git a/.github/workflows/gcc.yml b/.github/workflows/gcc.yml index 12614e57..9a33f037 100644 --- a/.github/workflows/gcc.yml +++ b/.github/workflows/gcc.yml @@ -32,7 +32,7 @@ jobs: run: bash scripts/download_doctest_header.sh -d include/ - name: build # use single thread to minimize memory usage, Process completed with exit code 137. - run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake ../.. && make -j2 VERBOSE=1' + run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake ../.. && make -j1 VERBOSE=1' - name: run tests run: | ./dockcross-${{ matrix.name }} bash -c 'build/${{ matrix.name }}/tests/array/numeric-tests-doctest' @@ -62,7 +62,7 @@ jobs: run: bash scripts/download_doctest_header.sh -d include/ - name: build # use single thread to minimize memory usage, Process completed with exit code 137. - run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DNMTOOLS_TESTING_GENERIC_NDARRAY=ON -DNMTOOLS_BUILD_VIEW_TESTS=ON ../.. && make -j2 VERBOSE=1 numeric-tests-view-doctest' + run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DNMTOOLS_TESTING_GENERIC_NDARRAY=ON -DNMTOOLS_BUILD_VIEW_TESTS=ON ../.. && make -j1 VERBOSE=1 numeric-tests-view-doctest' - name: run tests run: | ./dockcross-${{ matrix.name }} bash -c 'build/${{ matrix.name }}/tests/view/numeric-tests-view-doctest' @@ -87,7 +87,7 @@ jobs: run: bash scripts/download_doctest_header.sh -d include/ - name: build # use single thread to minimize memory usage, Process completed with exit code 137. - run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DNMTOOLS_BUILD_VIEW_TESTS=ON -DNMTOOLS_TESTING_NOSTL=ON ../.. && make -j2 VERBOSE=1 numeric-tests-view-doctest' + run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DNMTOOLS_BUILD_VIEW_TESTS=ON -DNMTOOLS_TESTING_NOSTL=ON ../.. && make -j1 VERBOSE=1 numeric-tests-view-doctest' - name: run tests run: | ./dockcross-${{ matrix.name }} bash -c 'build/${{ matrix.name }}/tests/view/numeric-tests-view-doctest' @@ -111,7 +111,7 @@ jobs: - name: setup doctest run: bash scripts/download_doctest_header.sh -d include/ - name: build - run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../../cmake/toolchains/gcc-werror.cmake -DNMTOOLS_TEST_ALL=OFF -DNMTOOLS_BUILD_INDEX_TESTS=ON ../.. && make -j2 VERBOSE=1 numeric-tests-index-doctest' + run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../../cmake/toolchains/gcc-werror.cmake -DNMTOOLS_TEST_ALL=OFF -DNMTOOLS_BUILD_INDEX_TESTS=ON ../.. && make -j1 VERBOSE=1 numeric-tests-index-doctest' - name: run tests run: | ./dockcross-${{ matrix.name }} bash -c 'build/${{ matrix.name }}/tests/index/numeric-tests-index-doctest' @@ -135,7 +135,7 @@ jobs: - name: setup doctest run: bash scripts/download_doctest_header.sh -d include/ - name: build - run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../../cmake/toolchains/gcc-werror.cmake -DNMTOOLS_TEST_ALL=OFF -DNMTOOLS_BUILD_FUNCTIONAL_TESTS=ON ../.. && make -j2 VERBOSE=1 numeric-tests-functional-doctest' + run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../../cmake/toolchains/gcc-werror.cmake -DNMTOOLS_TEST_ALL=OFF -DNMTOOLS_BUILD_FUNCTIONAL_TESTS=ON ../.. && make -j1 VERBOSE=1 numeric-tests-functional-doctest' - name: run tests run: | ./dockcross-${{ matrix.name }} bash -c 'build/${{ matrix.name }}/tests/functional/numeric-tests-functional-doctest' @@ -160,7 +160,7 @@ jobs: run: bash scripts/download_doctest_header.sh -d include/ - name: build # use single thread to minimize memory usage, Process completed with exit code 137. - run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DNMTOOLS_TESTING_GENERIC_NDARRAY=ON -DNMTOOLS_BUILD_VIEW_TESTS=ON -DNMTOOLS_TESTING_NOSTL=ON ../.. && make -j2 VERBOSE=1 numeric-tests-view-doctest' + run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DNMTOOLS_TESTING_GENERIC_NDARRAY=ON -DNMTOOLS_BUILD_VIEW_TESTS=ON -DNMTOOLS_TESTING_NOSTL=ON ../.. && make -j1 VERBOSE=1 numeric-tests-view-doctest' - name: run tests run: | ./dockcross-${{ matrix.name }} bash -c 'build/${{ matrix.name }}/tests/view/numeric-tests-view-doctest' @@ -184,7 +184,7 @@ jobs: - name: setup doctest run: bash scripts/download_doctest_header.sh -d include/ - name: build - run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DNMTOOLS_BUILD_META_TESTS=OFF -DNMTOOLS_BUILD_UTL_TESTS=OFF -DNMTOOLS_TEST_ALL=OFF -DNMTOOLS_TEST_ARRAY_EVAL=ON -DNMTOOLS_TESTING_GENERIC_NDARRAY=ON -DNMTOOLS_TESTING_NOSTL=ON ../.. && make -j2 VERBOSE=1' + run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DNMTOOLS_BUILD_META_TESTS=OFF -DNMTOOLS_BUILD_UTL_TESTS=OFF -DNMTOOLS_TEST_ALL=OFF -DNMTOOLS_TEST_ARRAY_EVAL=ON -DNMTOOLS_TESTING_GENERIC_NDARRAY=ON -DNMTOOLS_TESTING_NOSTL=ON ../.. && make -j1 VERBOSE=1' - name: run tests run: | ./dockcross-${{ matrix.name }} bash -c 'build/${{ matrix.name }}/tests/array/numeric-tests-doctest' @@ -208,7 +208,7 @@ jobs: - name: setup doctest run: bash scripts/download_doctest_header.sh -d include/ - name: build - run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DNMTOOLS_BUILD_META_TESTS=OFF -DNMTOOLS_BUILD_UTL_TESTS=OFF -DNMTOOLS_TEST_ALL=OFF -DNMTOOLS_TEST_ARRAY_EVAL=ON -DNMTOOLS_TESTING_GENERIC_NDARRAY=ON -DNMTOOLS_TESTING_NOSTL=OFF ../.. && make -j2 VERBOSE=1' + run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DNMTOOLS_BUILD_META_TESTS=OFF -DNMTOOLS_BUILD_UTL_TESTS=OFF -DNMTOOLS_TEST_ALL=OFF -DNMTOOLS_TEST_ARRAY_EVAL=ON -DNMTOOLS_TESTING_GENERIC_NDARRAY=ON -DNMTOOLS_TESTING_NOSTL=OFF ../.. && make -j1 VERBOSE=1' - name: run tests run: | ./dockcross-${{ matrix.name }} bash -c 'build/${{ matrix.name }}/tests/array/numeric-tests-doctest' @@ -232,7 +232,7 @@ jobs: - name: setup doctest run: bash scripts/download_doctest_header.sh -d include/ - name: build - run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DNMTOOLS_BUILD_CONSTEXPR_TESTS=ON -DNMTOOLS_BUILD_META_TESTS=OFF -DNMTOOLS_BUILD_UTL_TESTS=OFF -DNMTOOLS_TEST_ALL=OFF -DNMTOOLS_TEST_ARRAY_EVAL=ON ../.. && make -j2 VERBOSE=1' + run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DNMTOOLS_BUILD_CONSTEXPR_TESTS=ON -DNMTOOLS_BUILD_META_TESTS=OFF -DNMTOOLS_BUILD_UTL_TESTS=OFF -DNMTOOLS_TEST_ALL=OFF -DNMTOOLS_TEST_ARRAY_EVAL=ON ../.. && make -j1 VERBOSE=1' - name: run tests run: | ./dockcross-${{ matrix.name }} bash -c 'build/${{ matrix.name }}/tests/constexpr/numeric-tests-constexpr-doctest' @@ -256,7 +256,7 @@ jobs: - name: setup doctest run: bash scripts/download_doctest_header.sh -d include/ - name: build - run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DNMTOOLS_BUILD_CONSTEXPR_TESTS=ON -DNMTOOLS_BUILD_META_TESTS=OFF -DNMTOOLS_BUILD_UTL_TESTS=OFF -DNMTOOLS_TEST_ALL=OFF -DNMTOOLS_TEST_ARRAY_EVAL=ON -DNMTOOLS_TESTING_GENERIC_NDARRAY=ON -DNMTOOLS_TESTING_NOSTL=ON ../.. && make -j2 VERBOSE=1' + run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DNMTOOLS_BUILD_CONSTEXPR_TESTS=ON -DNMTOOLS_BUILD_META_TESTS=OFF -DNMTOOLS_BUILD_UTL_TESTS=OFF -DNMTOOLS_TEST_ALL=OFF -DNMTOOLS_TEST_ARRAY_EVAL=ON -DNMTOOLS_TESTING_GENERIC_NDARRAY=ON -DNMTOOLS_TESTING_NOSTL=ON ../.. && make -j1 VERBOSE=1' - name: run tests run: | ./dockcross-${{ matrix.name }} bash -c 'build/${{ matrix.name }}/tests/constexpr/numeric-tests-constexpr-doctest' @@ -280,7 +280,7 @@ jobs: - name: setup doctest run: bash scripts/download_doctest_header.sh -d include/ - name: build - run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DNMTOOLS_BUILD_CONSTEXPR_TESTS=ON -DNMTOOLS_BUILD_META_TESTS=OFF -DNMTOOLS_BUILD_UTL_TESTS=OFF -DNMTOOLS_TEST_ALL=OFF -DNMTOOLS_TEST_ARRAY_EVAL=ON -DNMTOOLS_TESTING_GENERIC_NDARRAY=ON -DNMTOOLS_TESTING_NOSTL=OFF ../.. && make -j2 VERBOSE=1' + run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DNMTOOLS_BUILD_CONSTEXPR_TESTS=ON -DNMTOOLS_BUILD_META_TESTS=OFF -DNMTOOLS_BUILD_UTL_TESTS=OFF -DNMTOOLS_TEST_ALL=OFF -DNMTOOLS_TEST_ARRAY_EVAL=ON -DNMTOOLS_TESTING_GENERIC_NDARRAY=ON -DNMTOOLS_TESTING_NOSTL=OFF ../.. && make -j1 VERBOSE=1' - name: run tests run: | ./dockcross-${{ matrix.name }} bash -c 'build/${{ matrix.name }}/tests/constexpr/numeric-tests-constexpr-doctest' \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6a54f8ee..468c158b 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,5 @@ pocl *.ll llvm.sh install -amdgpu-* \ No newline at end of file +amdgpu-* +*.dot \ No newline at end of file diff --git a/docs/compiler-notes.txt b/docs/compiler-notes.txt index 9c8c2db8..29a4a62b 100644 --- a/docs/compiler-notes.txt +++ b/docs/compiler-notes.txt @@ -16,7 +16,7 @@ Documenting various note on behaviour difference between clang & gcc (or with so https://godbolt.org/z/WYxahvxTx 1. constexpr math - error: constexpr function never produces a constant expression + error: constexpr function never produces a constant expression https://godbolt.org/z/dxqq3T 1. Constexpr if with a non-bool condition @@ -42,7 +42,7 @@ Documenting various note on behaviour difference between clang & gcc (or with so https://godbolt.org/z/asrh7q 1. clang and gcc disagree on if constexpr inside lambda - https://godbolt.org/z/8qc13s + https://godbolt.org/z/8qc13s https://stackoverflow.com/questions/59647445/if-constexpr-with-static-assert-in-lambda-which-compiler-is-correct 1. clang and gcc disagree on partial specialization & sfinae, makes ambiguous instantiation on gcc but no issue on clang @@ -97,4 +97,8 @@ Documenting various note on behaviour difference between clang & gcc (or with so 1. clang vs gcc disagree on constexpr evaluation (cumbersome to minimally reproduce, document as issue instead) - https://github.com/alifahrri/nmtools/issues/282 \ No newline at end of file + https://github.com/alifahrri/nmtools/issues/282 + +1. clang vs gcc disagree on capturing constexpr value in lambda expression + clang ok, gcc not ok + https://godbolt.org/z/a1o8P9957 \ No newline at end of file diff --git a/include/nmtools/array/array/atleast_nd.hpp b/include/nmtools/array/array/atleast_nd.hpp new file mode 100644 index 00000000..e874c237 --- /dev/null +++ b/include/nmtools/array/array/atleast_nd.hpp @@ -0,0 +1,34 @@ +#ifndef NMTOOLS_ARRAY_ARRAY_ATLEAST_ND_HPP +#define NMTOOLS_ARRAY_ARRAY_ATLEAST_ND_HPP + +#include "nmtools/array/view/atleast_nd.hpp" +#include "nmtools/array/eval.hpp" + +namespace nmtools::array +{ + /** + * @brief Eagerly compute atleast_nd. + * + * @tparam output_t + * @tparam context_t + * @tparam array_t + * @param array Input array + * @param context Evaluation context + * @param output + * @return constexpr auto + */ + template , + typename array_t, typename nd_t> + constexpr auto atleast_nd(const array_t& array, nd_t nd + , context_t&& context=context_t{}, output_t&& output=output_t{},meta::as_value resolver=meta::as_value_v) + { + auto viewed = view::atleast_nd(array,nd); + return eval(viewed + ,nmtools::forward(context) + ,nmtools::forward(output) + ,resolver + ); + } // atleast_nd +} // namespace nmtools::array + +#endif // NMTOOLS_ARRAY_ARRAY_ATLEAST_ND_HPP \ No newline at end of file diff --git a/include/nmtools/array/eval.hpp b/include/nmtools/array/eval.hpp index d2619d68..9205ae63 100644 --- a/include/nmtools/array/eval.hpp +++ b/include/nmtools/array/eval.hpp @@ -452,7 +452,7 @@ namespace nmtools::meta // default impl of make_fixed_ndarray only support integral constant for now using stype = ct; if constexpr (is_void_v) { - using type = make_tuple_type_t; + using type = nmtools_tuple; return as_value_v; } else { using type = append_type_t; @@ -496,7 +496,7 @@ namespace nmtools::meta // default impl of make_fixed_ndarray only support integral constant for now using stype = ct; if constexpr (is_void_v) { - using type = make_tuple_type_t; + using type = nmtools_tuple; return as_value_v; } else { using type = append_type_t; diff --git a/include/nmtools/array/functional.hpp b/include/nmtools/array/functional.hpp index 1e561037..7a178515 100644 --- a/include/nmtools/array/functional.hpp +++ b/include/nmtools/array/functional.hpp @@ -1,6 +1,8 @@ #ifndef NMTOOLS_ARRAY_FUNCTIONAL_HPP #define NMTOOLS_ARRAY_FUNCTIONAL_HPP +#include "nmtools/array/functional/indexing.hpp" + #include "nmtools/array/functional/activations/celu.hpp" #include "nmtools/array/functional/activations/elu.hpp" #include "nmtools/array/functional/activations/hardshrink.hpp" @@ -78,6 +80,5 @@ #include "nmtools/array/functional/squeeze.hpp" #include "nmtools/array/functional/where.hpp" #include "nmtools/array/functional/zeros.hpp" -#include "nmtools/array/functional/indexing.hpp" #endif // NMTOOLS_ARRAY_FUNCTIONAL_HPP \ No newline at end of file diff --git a/include/nmtools/array/functional/batch_norm.hpp b/include/nmtools/array/functional/batch_norm.hpp index 192874e9..759ba44f 100644 --- a/include/nmtools/array/functional/batch_norm.hpp +++ b/include/nmtools/array/functional/batch_norm.hpp @@ -2,14 +2,21 @@ #define NMTOOLS_ARRAY_FUNCTIONAL_BATCH_NORM_HPP #include "nmtools/array/functional/functor.hpp" +#include "nmtools/array/functional/moveaxis.hpp" +#include "nmtools/array/functional/ufuncs/add.hpp" +#include "nmtools/array/functional/ufuncs/multiply.hpp" +#include "nmtools/array/functional/ufuncs/subtract.hpp" +#include "nmtools/array/functional/ufuncs/divide.hpp" +#include "nmtools/array/functional/ufuncs/sqrt.hpp" #include "nmtools/array/view/batch_norm.hpp" namespace nmtools::functional { - constexpr inline auto batch_norm = functor_t{quinary_fmap_t{ - [](const auto&...args){ - return view::batch_norm(args...); - }}}; + constexpr inline auto batch_norm_fun = [](const auto&...args){ + return view::batch_norm(args...); + }; + + constexpr inline auto batch_norm = functor_t{quinary_fmap_t{batch_norm_fun}}; } // namespace nmtools::functional #endif // NMTOOLS_ARRAY_FUNCTIONAL_BATCH_NORM_HPP \ No newline at end of file diff --git a/include/nmtools/array/functional/compute_graph.hpp b/include/nmtools/array/functional/compute_graph.hpp new file mode 100644 index 00000000..58d44259 --- /dev/null +++ b/include/nmtools/array/functional/compute_graph.hpp @@ -0,0 +1,258 @@ +#ifndef NMTOOLS_ARRAY_FUNCTIONAL_COMPUTE_GRAPH_HPP +#define NMTOOLS_ARRAY_FUNCTIONAL_COMPUTE_GRAPH_HPP + +#include "nmtools/array/functional/functor.hpp" +#include "nmtools/array/view/ufunc/ufunc.hpp" +#include "nmtools/array/view/ufunc.hpp" + +namespace nmtools::functional +{ + template + struct get_compute_graph_t; + + template + constexpr auto get_compute_graph(const view_t& view) + { + if constexpr (meta::is_maybe_v) { + using view_type = meta::get_maybe_type_t; + using result_type = decltype(get_compute_graph(meta::declval())); + using return_type = nmtools_maybe; + if (static_cast(view)) { + return return_type{get_compute_graph(*view)}; + } else { + return return_type{meta::Nothing}; + } + } else { + using view_type = view_t; + auto get_graph = get_compute_graph_t{view}; + return get_graph(); + } + } // get_compute_graph + + template + struct node_t + { + // TODO: assert functor_t is functor or functor composition + // TODO: assert operands_t is tuple of integral constant + // TODO: record out_shape + + using functor_type = functor_t; + using operands_type = operands_t; + + functor_type functor; + operands_type operands; + }; + + template + node_t(const functor_t&, const operands_t&) -> node_t; + + template , typename edges_t=nmtools_tuple<>, typename node_data_t=nmtools_tuple<>> + struct compute_graph_t : utility::ct_digraph + { + // TODO: validate that node_data_t is tuple of node_t + using base_type = utility::ct_digraph; + }; + + template