Skip to content

Introduce BlockSize #3716

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

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5f80934
Introduce BlockSize concept
schnellerhase Apr 27, 2025
65ff61f
Use BlockSize in packing
schnellerhase Apr 27, 2025
a708e7d
Use BlockSize in vector assembly
schnellerhase Apr 27, 2025
5b65ad8
Adapt demo
schnellerhase Apr 27, 2025
29a1219
Introduce BS<> alias
schnellerhase Apr 27, 2025
10cc79c
Use BlockSize in spmv
schnellerhase Apr 27, 2025
1fb65d4
doc
schnellerhase Apr 27, 2025
dcfef33
Introduce generic ConstexprType
schnellerhase Apr 29, 2025
b8b0f90
value()
schnellerhase Apr 30, 2025
152e8d0
Add test case
schnellerhase Apr 30, 2025
0e2ad15
format
schnellerhase Apr 30, 2025
31a146d
constexpr value access
schnellerhase Apr 30, 2025
6a4d5b5
format
schnellerhase Apr 30, 2025
2652fb5
Bump PETSc/SLEPc
schnellerhase Apr 30, 2025
c762822
Revert "Bump PETSc/SLEPc"
schnellerhase Apr 30, 2025
796725c
Tidy up
schnellerhase Apr 30, 2025
7602862
Merge branch 'main' into block_size
schnellerhase Apr 30, 2025
460b350
Compiler limitation for floating point values
schnellerhase Apr 30, 2025
5c1d722
Misses year code
schnellerhase May 1, 2025
4f8f8ca
Merge branch 'main' into block_size
schnellerhase May 29, 2025
5f3d563
Even better
schnellerhase Jun 2, 2025
6f6cb9b
Missed one
schnellerhase Jun 2, 2025
c50ce56
Revert to constexpr
schnellerhase Jun 3, 2025
6e21ad1
Merge branch 'main' into block_size
schnellerhase Jun 29, 2025
865e8f1
Merge branch 'main' into block_size
garth-wells Jul 14, 2025
e8f9032
Merge branch 'main' into block_size
jhale Jul 18, 2025
6900e88
Try trait for constexpr type deduction
schnellerhase Jul 21, 2025
4e3367f
Revert "Try trait for constexpr type deduction"
schnellerhase Jul 21, 2025
cb756fa
Don't reimplement auto
schnellerhase Jul 21, 2025
d45a46f
Merge branch 'main' into block_size
schnellerhase Jul 21, 2025
60d0032
Switch all occurences to auto
schnellerhase Jul 21, 2025
617042c
Fix merge mess up
schnellerhase Jul 21, 2025
22f5402
Merge branch 'main' into block_size
schnellerhase Jul 22, 2025
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
7 changes: 4 additions & 3 deletions cpp/demo/custom_kernel/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <map>
#include <stdint.h>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -167,9 +168,9 @@ double assemble_vector1(const mesh::Geometry<T>& g, const fem::DofMap& dofmap,
md::mdspan<const T, md::extents<std::size_t, md::dynamic_extent, 3>> x(
g.x().data(), g.x().size() / 3, 3);
common::Timer timer("Assembler1 lambda (vector)");
fem::impl::assemble_cells<T, 1>([](auto, auto, auto, auto) {},
b.mutable_array(), g.dofmap(), x, cells,
{dofmap.map(), 1, cells}, kernel, {}, {}, {});
fem::impl::assemble_cells<T, BS<1>>(
[](auto, auto, auto, auto) {}, b.mutable_array(), g.dofmap(), x, cells,
{dofmap.map(), BS<1>(), cells}, kernel, {}, {}, {});
b.scatter_rev(std::plus<T>());
return la::squared_norm(b);
}
Expand Down
1 change: 1 addition & 0 deletions cpp/dolfinx/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(HEADERS_common
${CMAKE_CURRENT_SOURCE_DIR}/defines.h
${CMAKE_CURRENT_SOURCE_DIR}/constexpr_type.h
${CMAKE_CURRENT_SOURCE_DIR}/dolfinx_common.h
${CMAKE_CURRENT_SOURCE_DIR}/dolfinx_doc.h
${CMAKE_CURRENT_SOURCE_DIR}/IndexMap.h
Expand Down
53 changes: 53 additions & 0 deletions cpp/dolfinx/common/constexpr_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (C) 2025 Paul T. Kühner
//
// This file is part of DOLFINx (https://www.fenicsproject.org)
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#pragma once

#include <type_traits>

namespace dolfinx::common
{
/// @private Concept defining a variadic compile time or runtime variable. T
/// indicates the type that is stored and V the value. Either V equals T, i.e.
/// it is a runtime variable or V defines a compile time value V::value of type
/// T.
/// @tparam T type of the value to be stored.
/// @tparam V container type. Usually T for a runtime variable or a
/// std::integral_constant<T, ...> for a compile time constant.
template <typename T, typename V>
concept ConstexprType = std::is_same_v<T, V> || (requires {
typename V::value_type;
requires std::is_same_v<typename V::value_type, T>;
});

/// @private Check if ConstexprType holds a compile time constant.
template <typename T, typename V>
requires ConstexprType<T, V>
constexpr bool is_compile_time_v = !std::is_same_v<T, V>;

/// @private Check if ConstexprType holds a run time variable.
template <typename T, typename V>
requires ConstexprType<T, V>
constexpr bool is_runtime_v = std::is_same_v<T, V>;

/// @private Retrieve value of a compile time constant form a ConstexprType.
template <typename T, typename V>
requires ConstexprType<T, V>
constexpr T value(V /* container */,
typename std::enable_if_t<is_compile_time_v<T, V>>* = 0)
{
return V::value;
}

/// @private Retrieve value of runtime variable form a ConstexprType.
template <typename T, typename V>
requires ConstexprType<T, V>
T value(V container, typename std::enable_if_t<is_runtime_v<T, V>>* = 0)
{
return container;
}

} // namespace dolfinx::common
27 changes: 27 additions & 0 deletions cpp/dolfinx/common/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <basix/mdspan.hpp>
#include <complex>
#include <concepts>
#include <dolfinx/common/constexpr_type.h>
#include <type_traits>

namespace dolfinx
Expand Down Expand Up @@ -41,4 +42,30 @@ using scalar_value_t = typename scalar_value<T>::type;
/// @private mdspan/mdarray namespace
namespace md = MDSPAN_IMPL_STANDARD_NAMESPACE;

/// @private Concept capturing both compile time defined block sizes and runtime
/// ones.
template <typename V>
concept BlockSize = common::ConstexprType<int, V>;

/// @private Short notation for a compile time block size.
template <int N>
using BS = std::integral_constant<int, N>;

/// @private Retrieves the integral block size of a compile time block size.
template <BlockSize V>
constexpr int
block_size(V bs,
typename std::enable_if_t<common::is_compile_time_v<int, V>>* = 0)
{
return common::value<int, V>(bs);
}

/// @private Retrieves the integral block size of a runtime block size.
template <BlockSize V>
int block_size(V bs,
typename std::enable_if_t<common::is_runtime_v<int, V>>* = 0)
{
return common::value<int, V>(bs);
}

} // namespace dolfinx
2 changes: 1 addition & 1 deletion cpp/dolfinx/fem/FiniteElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ class FiniteElement
std::span<const std::uint32_t> cell_info,
std::int32_t cell, int data_block_size)
{
const int ebs = block_size();
auto ebs = block_size();
const std::size_t dof_count = data.size() / data_block_size;
for (int block = 0; block < data_block_size; ++block)
{
Expand Down
Loading
Loading