-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started to add implementation based on HPX
- added build system support and test infrastructure - added .clang-format configuration file - added BLAS1 add (1d and 2d) - added BLAS1 scale (1d and 2d) - added GitHub action
- Loading branch information
Showing
27 changed files
with
1,969 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Copyright (c) 2016 Thomas Heller | ||
# Copyright (c) 2016-2022 Hartmut Kaiser | ||
|
||
--- | ||
AccessModifierOffset: -4 | ||
AlignAfterOpenBracket: DontAlign | ||
AlignConsecutiveAssignments: false | ||
AlignConsecutiveDeclarations: false | ||
AlignEscapedNewlines: Right | ||
AlignOperands: false | ||
AlignTrailingComments: true | ||
AllowAllParametersOfDeclarationOnNextLine: false | ||
AllowShortBlocksOnASingleLine: false | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: Empty | ||
AllowShortIfStatementsOnASingleLine: false | ||
AllowShortLoopsOnASingleLine: false | ||
AlwaysBreakAfterDefinitionReturnType: None | ||
AlwaysBreakAfterReturnType: None | ||
AlwaysBreakBeforeMultilineStrings: false | ||
AlwaysBreakTemplateDeclarations: true | ||
BinPackArguments: true | ||
BinPackParameters: true | ||
BraceWrapping: | ||
AfterCaseLabel: true | ||
AfterClass: true | ||
AfterControlStatement: true | ||
AfterEnum: true | ||
AfterFunction: true | ||
AfterNamespace: false | ||
AfterObjCDeclaration: false | ||
AfterStruct: true | ||
AfterUnion: true | ||
AfterExternBlock: false | ||
BeforeCatch: true | ||
BeforeElse: true | ||
IndentBraces: false | ||
SplitEmptyFunction: false | ||
SplitEmptyRecord: false | ||
SplitEmptyNamespace: false | ||
BeforeLambdaBody: false | ||
BeforeWhile: false | ||
BreakBeforeBinaryOperators: None | ||
BreakBeforeBraces: Custom | ||
BreakBeforeInheritanceComma: true | ||
BreakBeforeTernaryOperators: false | ||
BreakStringLiterals: true | ||
ColumnLimit: 80 | ||
CommentPragmas: /// | ||
CompactNamespaces: true | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: false | ||
ConstructorInitializerIndentWidth : 2 | ||
ContinuationIndentWidth: 4 | ||
Cpp11BracedListStyle: true | ||
DerivePointerAlignment: false | ||
FixNamespaceComments: true | ||
IncludeCategories: | ||
- Regex: '^<hpx/config\.hpp>' | ||
Priority: 1 | ||
- Regex: '^<hpx/config/.*\.hpp>' | ||
Priority: 2 | ||
- Regex: '^<hpx/.*/config\.hpp>' | ||
Priority: 3 | ||
- Regex: '^<hpx/.*/config/defines\.hpp>' | ||
Priority: 4 | ||
- Regex: '^<hpx/.*\.hpp>' | ||
Priority: 5 | ||
- Regex: '^<hpx/parallel/.*\.hpp>' | ||
Priority: 6 | ||
- Regex: '^<.*' | ||
Priority: 7 | ||
- Regex: '.*' | ||
Priority: 8 | ||
IndentCaseLabels: false | ||
IndentWidth: 4 | ||
IndentWrappedFunctionNames: false | ||
KeepEmptyLinesAtTheStartOfBlocks: false | ||
Language: Cpp | ||
MaxEmptyLinesToKeep: 1 | ||
NamespaceIndentation: None | ||
PenaltyBreakBeforeFirstCallParameter: 1 | ||
PenaltyBreakComment: 300 | ||
PenaltyBreakFirstLessLess: 120 | ||
PenaltyBreakString: 1000 | ||
PenaltyExcessCharacter: 1000000 | ||
PenaltyReturnTypeOnItsOwnLine: 200 | ||
PointerAlignment: Left | ||
ReflowComments: false | ||
SortIncludes: true | ||
SpaceAfterCStyleCast: true | ||
SpaceAfterTemplateKeyword: true | ||
SpaceBeforeAssignmentOperators: true | ||
SpaceBeforeParens: ControlStatements | ||
SpaceInEmptyParentheses: false | ||
SpacesBeforeTrailingComments: 4 | ||
SpacesInAngles: false | ||
SpacesInContainerLiterals: false | ||
SpacesInCStyleCastParentheses: false | ||
SpacesInParentheses: false | ||
SpacesInSquareBrackets: false | ||
Standard: Cpp11 | ||
TabWidth: 4 | ||
UseTab: Never | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright (c) 2022 Hartmut Kaiser | ||
|
||
name: HPX Backend CI (Debug) | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
container: stellargroup/hpx:dev | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Configure | ||
shell: bash | ||
run: | | ||
cmake \ | ||
. \ | ||
-Bbuild \ | ||
-GNinja \ | ||
-DCMAKE_BUILD_TYPE=Debug \ | ||
-DLINALG_ENABLE_TESTS=On \ | ||
-DLINALG_ENABLE_HPX=On \ | ||
-DLINALG_ENABLE_HPX_DEFAULT=On \ | ||
-DHPX_DIR=/hpx/build/lib/cmake/HPX | ||
- name: Build | ||
shell: bash | ||
run: | | ||
make install | ||
- name: Test | ||
shell: bash | ||
run: | | ||
cd build | ||
ctest --output-on-failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright (c) 2022 Hartmut Kaiser | ||
|
||
function(linalg_add_example_hpx EXENAME) | ||
linalg_add_example(${EXENAME}) | ||
if(LINALG_ENABLE_HPX) | ||
target_link_libraries(${EXENAME} PRIVATE HPX::wrap_main) | ||
endif() | ||
set_target_properties(${EXENAME} PROPERTIES FOLDER "Examples/HPX") | ||
endfunction(linalg_add_example_hpx) | ||
|
||
linalg_add_example_hpx(add_hpx) | ||
#linalg_add_example_hpx(dot_hpx) | ||
#linalg_add_example_hpx(dotc_hpx) | ||
#linalg_add_example_hpx(idx_abs_max_hpx) | ||
#linalg_add_example_hpx(vector_norm2_hpx) | ||
#linalg_add_example_hpx(vector_abs_sum_hpx) | ||
#linalg_add_example_hpx(vector_sum_of_squares_hpx) | ||
linalg_add_example_hpx(scale_hpx) | ||
#linalg_add_example_hpx(matrix_vector_product_hpx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Copyright (c) 2022 Hartmut Kaiser | ||
|
||
#include <hpx/execution.hpp> | ||
#include <hpx/hpx_main.hpp> | ||
|
||
#include <experimental/linalg> | ||
#include <experimental/mdspan> | ||
|
||
#include <cstddef> | ||
#include <execution> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
template <class T1, class ScalarType> | ||
void print_elements( | ||
const T1& v, const std::vector<ScalarType>& gold, char const* policy_str) | ||
{ | ||
std::cout << "Using policy: " << policy_str << "\n"; | ||
for (std::size_t i = 0; i < v.size(); i++) | ||
{ | ||
std::cout << "computed = " << v(i) << " , gold = " << gold[i] << "\n"; | ||
} | ||
} | ||
|
||
void reset(auto z) | ||
{ | ||
for (std::size_t i = 0; i < z.extent(0); i++) | ||
{ | ||
z(i) = 0; | ||
} | ||
} | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
std::cout << "add example: calling HPX-kernels" << std::endl; | ||
|
||
std::size_t N = 50; | ||
|
||
using value_type = double; | ||
|
||
std::vector<value_type> x_data(N); | ||
std::vector<value_type> y_data(N); | ||
std::vector<value_type> z_data(N); | ||
|
||
value_type* x_ptr = x_data.data(); | ||
value_type* y_ptr = y_data.data(); | ||
value_type* z_ptr = z_data.data(); | ||
|
||
using dyn_1d_ext_type = | ||
std::experimental::extents<std::experimental::dynamic_extent>; | ||
using mdspan_type = std::experimental::mdspan<value_type, dyn_1d_ext_type>; | ||
mdspan_type x(x_ptr, N); | ||
mdspan_type y(y_ptr, N); | ||
mdspan_type z(z_ptr, N); | ||
|
||
std::vector<value_type> gold(N); | ||
for (std::size_t i = 0; i < x.extent(0); i++) | ||
{ | ||
x(i) = static_cast<value_type>(i); | ||
y(i) = i + static_cast<value_type>(10); | ||
z(i) = 0; | ||
gold[i] = x(i) + y(i); | ||
} | ||
|
||
namespace stdla = std::experimental::linalg; | ||
const value_type init_value = 2.0; | ||
|
||
// This goes to the base implementation | ||
{ | ||
stdla::add(std::execution::seq, x, y, z); | ||
print_elements(z, gold, "std::execution::seq"); | ||
} | ||
|
||
// This also goes to the base implementation | ||
{ | ||
reset(z); // reset z since it is modified above | ||
stdla::add(hpx::execution::seq, x, y, z); | ||
print_elements(z, gold, "hpx::execution::seq"); | ||
} | ||
|
||
// This forwards to HPXKernels | ||
{ | ||
reset(z); // reset z since it is modified above | ||
stdla::add(HPXKernelsSTD::hpx_exec<>(), x, y, z); | ||
print_elements(z, gold, "HPXKernelsSTD::hpx_exec<>()"); | ||
} | ||
|
||
// This forwards to HPXKernels if LINALG_ENABLE_HPX_DEFAULT is ON | ||
{ | ||
reset(z); // reset z since it is modified above | ||
stdla::add(std::execution::par, x, y, z); | ||
print_elements(z, gold, "std::execution::par"); | ||
} | ||
|
||
// This forwards to HPXKernels | ||
{ | ||
reset(z); // reset z since it is modified above | ||
stdla::add(hpx::execution::par, x, y, z); | ||
print_elements(z, gold, "hpx::execution::par"); | ||
} | ||
|
||
#if defined(HPX_HAVE_DATAPAR) | ||
// this invokes a explicitly vectorized HPX versions | ||
{ | ||
reset(z); // reset z since it is modified above | ||
stdla::add(hpx::execution::simd, x, y, z); | ||
print_elements(z, gold, "hpx::execution::simd"); | ||
} | ||
|
||
{ | ||
reset(z); // reset z since it is modified above | ||
stdla::add(hpx::execution::par_simd, x, y, z); | ||
print_elements(z, gold, "hpx::execution::par_simd"); | ||
} | ||
#endif | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2022 Hartmut Kaiser | ||
|
||
#include <hpx/execution.hpp> | ||
#include <hpx/hpx_main.hpp> | ||
|
||
#include <experimental/linalg> | ||
#include <experimental/mdspan> | ||
|
||
#include <iostream> | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
std::cout << "dot example: calling hpx-kernels" << std::endl; | ||
|
||
std::size_t N = 40; | ||
{ | ||
std::vector<double> data(N); | ||
double* a_ptr = data.data(); | ||
|
||
// Requires CTAD working, GCC 11.1 works but some others are buggy | ||
// std::experimental::mdspan a(a_ptr,N); | ||
std::experimental::mdspan<double, | ||
std::experimental::extents<std::experimental::dynamic_extent>> | ||
a(a_ptr, N); | ||
for (std::size_t i = 0; i < a.extent(0); i++) | ||
a(i) = double(i); | ||
|
||
// This forwards to HPXKernels | ||
std::experimental::linalg::scale(HPXKernelsSTD::hpx_exec<>(), 2.0, a); | ||
// This forwards to HPXKernels if LINALG_ENABLE_HPX_DEFAULT is ON | ||
std::experimental::linalg::scale(std::execution::par, 2.0, a); | ||
// This always forwards to HPXKernels | ||
std::experimental::linalg::scale(hpx::execution::par, 2.0, a); | ||
// This goes to the base implementation | ||
std::experimental::linalg::scale(std::execution::seq, 2.0, a); | ||
// This also goes to the base implementation | ||
std::experimental::linalg::scale(hpx::execution::seq, 2.0, a); | ||
#if defined(HPX_HAVE_DATAPAR) | ||
// this invokes a explicitly vectorized version | ||
std::experimental::linalg::scale(hpx::execution::simd, 2.0, a); | ||
std::experimental::linalg::scale(hpx::execution::par_simd, 2.0, a); | ||
#endif | ||
for (std::size_t i = 0; i < a.extent(0); i++) | ||
printf("%zi %lf\n", i, a(i)); | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.