Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/context #122

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fail-fast: false
steps:
- name: Fetch current branch
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Prepare KIWAKU
run: |
mkdir build && cd build
Expand All @@ -30,7 +30,7 @@ jobs:
ninja doxygen

- name: Deploy to gh-pages
uses: peaceiris/actions-gh-pages@v3
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build/docs
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- {test: CPM , mode: 2 }
steps:
- name: Fetch current branch
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Check KIWAKU works with ${{ matrix.cfg.test }}
uses: ./.github/actions/integration
with:
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
gcc-linux:
runs-on: [ubuntu-latest]
container:
image: ghcr.io/jfalcou/compilers:v6
image: ghcr.io/jfalcou/compilers:v7
strategy:
fail-fast: false
matrix:
Expand All @@ -26,7 +26,7 @@ jobs:
- { opts: -Ofast -flto=auto -DNDEBUG }
steps:
- name: Fetch current branch
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Kiwaku using g++-12 with ${{ matrix.cfg.opts }}
run: |
mkdir build
Expand All @@ -40,7 +40,7 @@ jobs:
clang-linux:
runs-on: [ubuntu-latest]
container:
image: ghcr.io/jfalcou/compilers:v6
image: ghcr.io/jfalcou/compilers:v7
strategy:
fail-fast: false
matrix:
Expand All @@ -51,7 +51,7 @@ jobs:
- { opts: "-O0 -stdlib=libc++" , linker: -stdlib=libc++ }
steps:
- name: Fetch current branch
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Running CMake for clang++ with ${{ matrix.cfg.opts }}
run: |
mkdir build && cd build
Expand All @@ -62,7 +62,7 @@ jobs:
run: cd build && ctest --output-on-failure -j 2

clang-macosx:
runs-on: [macos-12]
runs-on: [macos-14]
strategy:
fail-fast: false
matrix:
Expand All @@ -73,7 +73,7 @@ jobs:
- { opts: "-Ofast -flto -DNDEBUG -stdlib=libc++", linker: -stdlib=libc++ }
steps:
- name: Fetch current branch
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Running CMake for clang++ with ${{ matrix.cfg.opts }}
run: |
mkdir build && cd build
Expand All @@ -84,7 +84,7 @@ jobs:
run: cd build && ctest --output-on-failure -j 2

gcc-macosx:
runs-on: [macos-11]
runs-on: [macos-14]
strategy:
fail-fast: false
matrix:
Expand All @@ -93,18 +93,18 @@ jobs:
- { opts: -Ofast -flto -DNDEBUG }
steps:
- name: Fetch current branch
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Running CMake for g++ with ${{ matrix.cfg.opts }}
run: |
mkdir build && cd build
cmake .. -DCMAKE_CXX_COMPILER=g++-11 -DCMAKE_CXX_FLAGS="${{ matrix.cfg.opts }}"
cmake .. -DCMAKE_CXX_COMPILER=g++-14 -DCMAKE_CXX_FLAGS="${{ matrix.cfg.opts }}"
- name: Compiling Unit Tests
run: cd build && make unit -j 2
- name: Running Unit Tests
run: cd build && ctest --output-on-failure -j 2

android:
runs-on: [macos-12]
runs-on: [macos-14]
strategy:
fail-fast: false
matrix:
Expand All @@ -113,7 +113,7 @@ jobs:
- { opts: -Ofast -flto -DNDEBUG }
steps:
- name: Fetch current branch
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Running CMake for g++ with ${{ matrix.cfg.opts }}
run: |
mkdir build && cd build
Expand All @@ -131,7 +131,7 @@ jobs:
# - { mode: Release}
# steps:
# - name: Fetch current branch
# uses: actions/checkout@v3
# uses: actions/checkout@v4
# - name: Running CMake for MSVC ${{ matrix.cfg.mode }}
# run: |
# mkdir build && cd build
Expand Down
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,15 @@ doc/conf.py
.vscode/*
.cache/*
.ideas/*


test/sycl_sandbox/obsolete
test/sycl_sandbox/test_templates_include.hpp
test/sycl_sandbox/test_templates.cpp
exec.sh
*.save
*.txt
*.save*

*.inactive
*.ignore
91 changes: 64 additions & 27 deletions include/kwk/algorithm/algos/binary_search.hpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
//==================================================================================================
//======================================================================================================================
/**
KIWAKU - Containers Well Made
Copyright : KIWAKU Project Contributors
SPDX-License-Identifier: BSL-1.0
**/
//==================================================================================================
//======================================================================================================================
#pragma once

#include <kwk/container.hpp>
#include <kwk/context/context.hpp>
#include <kwk/utility/coordinates.hpp>
#include <kwk/algorithm/algos/for_each.hpp>
#include <kwk/detail/abi.hpp>
#include <cstddef>
#include <utility>
#include <optional>

// ALGO:
/*
equal_range // view entre les deux boundss
*/

// trouver un moyen malin de calculer la position
// échanger de place func et non func et appeler func
namespace kwk
{
template <typename Func, concepts::container Out>
constexpr auto lower_bound(Out const& out, auto value, Func func)

// Unused context
// Function overloaded, even if Context is not used: for overloading with other contexts.
// eg.:
// constexpr auto lower_bound(sycl::context& c, Out const& out, auto value, Func func)
template <typename Context, typename Func, concepts::container Out>
constexpr std::optional<std::array<int,Out::static_order>>
lower_bound(Context&, Out const& out, auto value, Func func)
{
if (out.numel() == 0) return std::nullopt;

auto count = out.numel();
auto first = 0;
auto it = 0;
Expand All @@ -48,18 +53,29 @@ namespace kwk
else
count = step;
}
return (first < out.numel()) ? std::optional<std::array<int,Out::static_order>>{kwk::coordinates(it, out.shape())}
return (first < out.numel()) ? std::optional<std::array<int,Out::static_order>>{kwk::coordinates(it, out.shape())}
: std::nullopt;
}
template <typename Func, concepts::container Out>
constexpr auto lower_bound(Out const& out, auto value, Func func)
{
return lower_bound(cpu, out, value, func); // Unused context
}

template <typename Context, concepts::container Out>
constexpr auto lower_bound(Context& ctx, Out const& out, auto value)
{
return lower_bound(ctx, out, value, [](auto e, auto i){return e<i;});
}
template <concepts::container Out>
constexpr auto lower_bound(Out const& out, auto value)
{
return lower_bound(out, value, [](auto e, auto i){return e<i;});
return lower_bound(cpu, out, value);
}

template <typename Func, concepts::container Out>
constexpr auto upper_bound(Out const& out, auto value, Func func)
// Unused context
template <typename Context, typename Func, concepts::container Out>
constexpr auto upper_bound(Context&, Out const& out, auto value, Func func)
{
auto count = out.numel();
auto first = 0;
Expand All @@ -82,38 +98,59 @@ namespace kwk
else
count = step;
}
return (first < out.numel()) ? std::optional<std::array<int,Out::static_order>>{kwk::coordinates(it, out.shape())}
return (first < out.numel()) ? std::optional<std::array<int,Out::static_order>>{kwk::coordinates(it, out.shape())}
: std::nullopt;
}
template <typename Func, concepts::container Out>
constexpr auto upper_bound(Out const& out, auto value, Func func)
{
return upper_bound(cpu, out, value, func);
}


template <typename Context, concepts::container Out>
constexpr auto upper_bound(Context& ctx, Out const& out, auto value)
{
return upper_bound(ctx, out, value, [](auto e, auto i){return e<i;});
}
template <concepts::container Out>
constexpr auto upper_bound(Out const& out, auto value)
{
return upper_bound( out, value, [](auto e, auto i){return e<i;});
return upper_bound(cpu, out, value);
}

template <typename Func, concepts::container Out>
constexpr bool binary_search(Out const& out, auto value, Func func)

template <typename Context, typename Func, concepts::container Out>
constexpr bool binary_search(Context& ctx, Out const& out, auto value, Func func)
{
auto first = kwk::coordinates(0, out.shape());
auto f = std::apply([](auto... i) { return kumi::tuple{i...}; }, first);
// Finds the index of the first element before (or equal to) value
// returns an std::array<int, dimensions>
auto first = lower_bound(ctx, out, value, func);

if (func(value, out(f))) return false;
// Element not found
if (first == std::nullopt) return false;

auto p = kwk::lower_bound(out, value, func);
bool outbound;
// transforms the array into a kumi::tuple
auto kumi_findex = std::apply([](auto... i) { return kumi::tuple{i...}; }, *first);

if(p)
outbound = false;
else
outbound = true;
// return (out(kumi_findex) == value);
return !(func(value, out(kumi_findex)));

return (!outbound);
}
template <typename Func, concepts::container Out>
constexpr bool binary_search(Out const& out, auto value, Func func)
{
return binary_search(cpu, out, value, func);
}

template <typename Context, concepts::container Out>
constexpr bool binary_search(Context& ctx, Out const& out, auto value)
{
return binary_search(ctx, out, value, [](auto e, auto i){return e<i;});
}
template <concepts::container Out>
constexpr bool binary_search(Out const& out, auto value)
{
return binary_search(out, value, [](auto e, auto i){return e<i;});
return binary_search(cpu, out, value);
}
}
29 changes: 23 additions & 6 deletions include/kwk/algorithm/algos/copy.hpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
//==================================================================================================
//======================================================================================================================
/**
KIWAKU - Containers Well Made
Copyright : KIWAKU Project Contributors
SPDX-License-Identifier: BSL-1.0
**/
//==================================================================================================
//======================================================================================================================
#pragma once

#include <kwk/concepts/container.hpp>
#include <kwk/context/context.hpp>
#include <kwk/algorithm/algos/transform.hpp>
#include <kwk/algorithm/algos/for_each.hpp>
#include <kwk/detail/abi.hpp>
#include <cstddef>
#include <utility>

namespace kwk
{

template<typename Context, concepts::container Out, concepts::container In>
constexpr auto copy(Context& ctx, Out& out, In const& in)
{
kwk::transform(ctx, [](auto in) { return in; }, out, KWK_FWD(in) );
}

template<concepts::container Out, concepts::container In>
constexpr auto copy(Out& out, In&& in)
constexpr auto copy(Out& out, In const& in)
{
kwk::copy(cpu, out, in);
}


template<typename Context, typename Func, concepts::container Out, concepts::container In>
constexpr auto copy_if(Context& ctx, Func f, Out& out, In const& in)
{
kwk::transform([](auto in) { return in; }, out, KWK_FWD(in) );
// kwk::for_each(ctx, [&](auto... is) { if(f(in(is...))) out(is...) = KWK_FWD(in)(is...); }, out.shape() );
ctx.map([f](auto& o, auto const& i) { if(f(i)) o = i; }, ctx.out(out), ctx.in(in));
}

template<typename Func, concepts::container Out, concepts::container In>
constexpr auto copy_if(Func f, Out& out, In&& in)
constexpr auto copy_if(Func f, Out& out, In const& in)
{
kwk::for_each([&](auto... is) { if(f(in(is...))) out(is...) = KWK_FWD(in)(is...); }, out.shape() );
kwk::copy_if(cpu, f, out, in);
}
}
Loading