Skip to content

Commit 84a1557

Browse files
Buffer API update (#141)
* update to new buffer API * Committing clang-format changes --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 961f83e commit 84a1557

File tree

6 files changed

+38
-35
lines changed

6 files changed

+38
-35
lines changed

src/integrals/ao_integrals/coulomb_metric.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct Kernel {
3030
// Unwrap buffer info
3131
tensorwrapper::allocator::Eigen<FloatType> allocator(rv);
3232
const auto& eigen_I = allocator.rebind(I);
33-
const auto* pI = eigen_I.data();
33+
const auto* pI = eigen_I.get_immutable_data();
3434
const auto& shape_I = eigen_I.layout().shape().as_smooth();
3535
auto rows = shape_I.extent(0);
3636
auto cols = shape_I.extent(1);
@@ -49,8 +49,10 @@ struct Kernel {
4949
tensorwrapper::shape::Smooth matrix_shape{rows, cols};
5050
tensorwrapper::layout::Physical matrix_layout(matrix_shape);
5151
auto pM_buffer = allocator.allocate(matrix_layout);
52-
for(auto i = 0; i < rows; ++i) {
53-
for(auto j = 0; j < cols; ++j) { pM_buffer->at(i, j) = Linv(i, j); }
52+
for(decltype(rows) i = 0; i < rows; ++i) {
53+
for(decltype(cols) j = 0; j < cols; ++j) {
54+
pM_buffer->set_elem({i, j}, Linv(i, j));
55+
}
5456
}
5557
return simde::type::tensor(matrix_shape, std::move(pM_buffer));
5658
}

src/integrals/ao_integrals/uq_driver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ struct Kernel {
3434

3535
auto rv_buffer = alloc.allocate(t_eigen.layout());
3636
for(std::size_t i = 0; i < t_eigen.size(); ++i) {
37-
const auto elem = (t_eigen.data() + i)->mean();
38-
const auto elem_error = (error_eigen.data() + i)->mean();
39-
*(rv_buffer->data() + i) = FloatType(elem, elem_error);
37+
const auto elem = t_eigen.get_data(i).mean();
38+
const auto elem_error = error_eigen.get_data(i).mean();
39+
rv_buffer->set_data(i, FloatType(elem, elem_error));
4040
}
4141

4242
const auto& shape = t_eigen.layout().shape();

src/integrals/libint/libint.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ auto fill_tensor(const std::vector<libint2::BasisSet>& basis_sets,
7575
auto ord = detail_::shells2ord(basis_sets, shells);
7676
auto n_ord = ord.size();
7777
for(decltype(n_ord) i_ord = 0; i_ord < n_ord; ++i_ord) {
78-
pbuffer->data()[ord[i_ord]] += vals[i_ord];
78+
auto update = pbuffer->get_data(ord[i_ord]) + vals[i_ord];
79+
pbuffer->set_data(ord[i_ord], update);
7980
}
8081
}
8182

tests/cxx/unit/integrals/ao_integrals/ao_integrals_driver.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ void compare_matrices(const tensor& A, const tensor& A_corr) {
2626
const auto& A_corr_buffer = alloc_type::rebind(A_corr.buffer());
2727

2828
const auto tol = 1E-6;
29-
auto A00 = A_buffer.at(0, 0);
30-
auto A01 = A_buffer.at(0, 1);
31-
auto A10 = A_buffer.at(1, 0);
32-
auto A11 = A_buffer.at(1, 1);
33-
34-
REQUIRE(A00 == Catch::Approx(A_corr_buffer.at(0, 0)).margin(tol));
35-
REQUIRE(A01 == Catch::Approx(A_corr_buffer.at(0, 1)).margin(tol));
36-
REQUIRE(A10 == Catch::Approx(A_corr_buffer.at(1, 0)).margin(tol));
37-
REQUIRE(A11 == Catch::Approx(A_corr_buffer.at(1, 1)).margin(tol));
29+
auto A00 = A_buffer.get_elem({0, 0});
30+
auto A01 = A_buffer.get_elem({0, 1});
31+
auto A10 = A_buffer.get_elem({1, 0});
32+
auto A11 = A_buffer.get_elem({1, 1});
33+
34+
REQUIRE(A00 == Catch::Approx(A_corr_buffer.get_elem({0, 0})).margin(tol));
35+
REQUIRE(A01 == Catch::Approx(A_corr_buffer.get_elem({0, 1})).margin(tol));
36+
REQUIRE(A10 == Catch::Approx(A_corr_buffer.get_elem({1, 0})).margin(tol));
37+
REQUIRE(A11 == Catch::Approx(A_corr_buffer.get_elem({1, 1})).margin(tol));
3838
}
3939

4040
} // namespace

tests/cxx/unit/integrals/ao_integrals/test_uq_driver.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@ auto corr_answer(const simde::type::tensor& T) {
2222
return T;
2323
} else {
2424
simde::type::tensor T_corr(T);
25-
using alloc_type = tensorwrapper::allocator::Eigen<FloatType>;
26-
auto& corr_buffer = alloc_type::rebind(T_corr.buffer());
27-
corr_buffer.at(0, 0, 0, 0) = FloatType{0.774606, 0};
28-
corr_buffer.at(0, 0, 0, 1) = FloatType{0.265558, 2.49687e-06};
29-
corr_buffer.at(0, 0, 1, 0) = FloatType{0.265558, 2.49687e-06};
30-
corr_buffer.at(0, 0, 1, 1) = FloatType{0.446701, 0};
31-
corr_buffer.at(0, 1, 0, 0) = FloatType{0.265558, 2.49687e-06};
32-
corr_buffer.at(0, 1, 0, 1) = FloatType{0.120666, 1.10748e-05};
33-
corr_buffer.at(0, 1, 1, 0) = FloatType{0.120666, 1.10748e-05};
34-
corr_buffer.at(0, 1, 1, 1) = FloatType{0.265558, 2.49687e-06};
35-
corr_buffer.at(1, 0, 0, 0) = FloatType{0.265558, 2.49687e-06};
36-
corr_buffer.at(1, 0, 0, 1) = FloatType{0.120666, 1.10748e-05};
37-
corr_buffer.at(1, 0, 1, 0) = FloatType{0.120666, 1.10748e-05};
38-
corr_buffer.at(1, 0, 1, 1) = FloatType{0.265558, 2.49687e-06};
39-
corr_buffer.at(1, 1, 0, 0) = FloatType{0.446701, 0};
40-
corr_buffer.at(1, 1, 0, 1) = FloatType{0.265558, 2.49687e-06};
41-
corr_buffer.at(1, 1, 1, 0) = FloatType{0.265558, 2.49687e-06};
42-
corr_buffer.at(1, 1, 1, 1) = FloatType{0.774606, 0};
25+
using alloc_type = tensorwrapper::allocator::Eigen<FloatType>;
26+
auto& corr_buffer = alloc_type::rebind(T_corr.buffer());
27+
corr_buffer.set_elem({0, 0, 0, 0}, FloatType{0.774606, 0});
28+
corr_buffer.set_elem({0, 0, 0, 1}, FloatType{0.265558, 2.49687e-06});
29+
corr_buffer.set_elem({0, 0, 1, 0}, FloatType{0.265558, 2.49687e-06});
30+
corr_buffer.set_elem({0, 0, 1, 1}, FloatType{0.446701, 0});
31+
corr_buffer.set_elem({0, 1, 0, 0}, FloatType{0.265558, 2.49687e-06});
32+
corr_buffer.set_elem({0, 1, 0, 1}, FloatType{0.120666, 1.10748e-05});
33+
corr_buffer.set_elem({0, 1, 1, 0}, FloatType{0.120666, 1.10748e-05});
34+
corr_buffer.set_elem({0, 1, 1, 1}, FloatType{0.265558, 2.49687e-06});
35+
corr_buffer.set_elem({1, 0, 0, 0}, FloatType{0.265558, 2.49687e-06});
36+
corr_buffer.set_elem({1, 0, 0, 1}, FloatType{0.120666, 1.10748e-05});
37+
corr_buffer.set_elem({1, 0, 1, 0}, FloatType{0.120666, 1.10748e-05});
38+
corr_buffer.set_elem({1, 0, 1, 1}, FloatType{0.265558, 2.49687e-06});
39+
corr_buffer.set_elem({1, 1, 0, 0}, FloatType{0.446701, 0});
40+
corr_buffer.set_elem({1, 1, 0, 1}, FloatType{0.265558, 2.49687e-06});
41+
corr_buffer.set_elem({1, 1, 1, 0}, FloatType{0.265558, 2.49687e-06});
42+
corr_buffer.set_elem({1, 1, 1, 1}, FloatType{0.774606, 0});
4343
return T_corr;
4444
}
4545
}

tests/cxx/unit/integrals/testing.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ auto eigen_tensor_(const tensorwrapper::buffer::BufferBase& buffer,
3333
std::array<int, N> extents, std::index_sequence<Is...>) {
3434
const auto& b = tensorwrapper::allocator::Eigen<FloatType>::rebind(buffer);
3535
using eigen_type = Eigen::Tensor<const FloatType, N, Eigen::RowMajor>;
36-
return Eigen::TensorMap<eigen_type>(b.data(), extents[Is]...);
36+
return Eigen::TensorMap<eigen_type>(b.get_immutable_data(), extents[Is]...);
3737
}
3838

3939
// Checking eigen outputs

0 commit comments

Comments
 (0)