Skip to content

Commit

Permalink
Update compute-graph capture (#286)
Browse files Browse the repository at this point in the history
* update compiler notes

* suport arbitrary sized utl tuple

* add type_name metafunction to get typename at compile-time

* restructure compute_graph & functor files & deps

* new aliasing logic using compile-time hashing

* update tests

* fix hip compilation

* try to fix risc-v ci

* temporarily allow matmul test to fail on sycl (for pocl)

* reduce compilation jobs to avoid oom on gcc
  • Loading branch information
alifahrri committed Jul 7, 2024
1 parent a1b6f10 commit bcc2ddc
Show file tree
Hide file tree
Showing 143 changed files with 4,510 additions and 2,790 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ pocl
*.ll
llvm.sh
install
amdgpu-*
amdgpu-*
*.dot
10 changes: 7 additions & 3 deletions docs/compiler-notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
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
34 changes: 34 additions & 0 deletions include/nmtools/array/array/atleast_nd.hpp
Original file line number Diff line number Diff line change
@@ -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 output_t=none_t, typename context_t=none_t, typename resolver_t=eval_result_t<>,
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_t> resolver=meta::as_value_v<resolver_t>)
{
auto viewed = view::atleast_nd(array,nd);
return eval(viewed
,nmtools::forward<context_t>(context)
,nmtools::forward<output_t>(output)
,resolver
);
} // atleast_nd
} // namespace nmtools::array

#endif // NMTOOLS_ARRAY_ARRAY_ATLEAST_ND_HPP
4 changes: 2 additions & 2 deletions include/nmtools/array/eval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ namespace nmtools::meta
// default impl of make_fixed_ndarray only support integral constant for now
using stype = ct<s>;
if constexpr (is_void_v<type>) {
using type = make_tuple_type_t<stype>;
using type = nmtools_tuple<stype>;
return as_value_v<type>;
} else {
using type = append_type_t<type,stype>;
Expand Down Expand Up @@ -496,7 +496,7 @@ namespace nmtools::meta
// default impl of make_fixed_ndarray only support integral constant for now
using stype = ct<s>;
if constexpr (is_void_v<type>) {
using type = make_tuple_type_t<stype>;
using type = nmtools_tuple<stype>;
return as_value_v<type>;
} else {
using type = append_type_t<type,stype>;
Expand Down
3 changes: 2 additions & 1 deletion include/nmtools/array/functional.hpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
15 changes: 11 additions & 4 deletions include/nmtools/array/functional/batch_norm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<decltype(batch_norm_fun)>{batch_norm_fun}};
} // namespace nmtools::functional

#endif // NMTOOLS_ARRAY_FUNCTIONAL_BATCH_NORM_HPP
Loading

0 comments on commit bcc2ddc

Please sign in to comment.