Skip to content
Merged
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
31 changes: 21 additions & 10 deletions src/SliceWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ struct SliceWrapper {
SliceWrapper(SliceType st) : st_(st) {}

KOKKOS_INLINE_FUNCTION
T& access(const int s, const int a, int i) const {
return st_.access(s,a,i);
T& access(const int s, const int a) const {
return st_.access(s,a);
}
int arraySize(int s) {
return st_.arraySize(s);
Expand All @@ -24,23 +24,34 @@ struct SliceWrapper {

using namespace Cabana;

template <class ExecutionSpace, class MemorySpace, class T, int width, int vecLen>
template <class ExecutionSpace, class MemorySpace, class... Ts>
class CabSliceFactory {
static constexpr int vecLen = Impl::PerformanceTraits<ExecutionSpace>::vector_length/8;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the division by 8? Is the vector_length reported in bits?

Can you point me at where Cabana uses this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I divided it by eight because when I changed to this vector length instead of the user defined one, the stride calculation got messed up, being eight times larger than it should have been which gave me errors. I have just revised the calculation to be correct and not divide the vector length by 8.

Cabana uses this here as a default template parameter for the AoSoA
https://github.com/ECP-copa/Cabana/blob/1c44a7fef24b61f73e629ddd2084c4d05b0ec977/core/src/Cabana_AoSoA.hpp#L146:~:text=int%20VectorLength%20%3D%20Impl,DeviceType%3A%3Aexecution_space%3E%3A%3Avector_length

using TypeTuple = std::tuple<Ts...>;
using DeviceType = Kokkos::Device<ExecutionSpace, MemorySpace>;
using DataTypes = Cabana::MemberTypes<T[width]>;
using DataTypes = Cabana::MemberTypes<Ts...>;
using soa_t = SoA<DataTypes, vecLen>;

template <class T, int stride>
using member_slice_t =
Cabana::Slice<T[width], DeviceType,
Cabana::Slice<T, DeviceType,
Cabana::DefaultAccessMemory,
vecLen, width*vecLen>;
using wrapper_slice_t = SliceWrapper<member_slice_t, T>;
vecLen, stride>;

template <class T, int stride>
using wrapper_slice_t = SliceWrapper<member_slice_t<T, stride>, T>;

Cabana::AoSoA<DataTypes, DeviceType, vecLen> aosoa;

public:
wrapper_slice_t makeSliceCab() {
auto slice0 = Cabana::slice<0>(aosoa);
return wrapper_slice_t(std::move(slice0));
template <std::size_t index>
auto makeSliceCab() {
using type = std::tuple_element_t<index, TypeTuple>;
const int stride = (vecLen * sizeof(soa_t)) / (4 * sizeof(type));
auto slice = Cabana::slice<index>(aosoa);
return wrapper_slice_t< type, stride >(std::move(slice));
}

CabSliceFactory(int n) : aosoa("sliceAoSoA", n) {}
};

Expand Down
31 changes: 17 additions & 14 deletions test/SliceWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,37 @@
int main(int argc, char* argv[]) {
// AoSoA parameters
const int vecLen = 4;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this still be here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope. It will be removed in the next version

const int width = 1;
int num_tuples = 10;

Kokkos::ScopeGuard scope_guard(argc, argv);

using member_type = double;
using DataTypes = Cabana::MemberTypes<member_type[width]>;
using ExecutionSpace = Kokkos::Cuda;
using MemorySpace = Kokkos::CudaSpace;

using ExecutionSpace = Kokkos::DefaultExecutionSpace;
using MemorySpace = ExecutionSpace::memory_space;

// Slice Wrapper Factory
CabSliceFactory<ExecutionSpace, MemorySpace,
member_type, width, vecLen> cabSliceFactory(num_tuples);
double, int, float, char> cabSliceFactory(num_tuples);

auto slice_wrapper = cabSliceFactory.makeSliceCab();
auto slice_wrapper0 = cabSliceFactory.makeSliceCab<0>();
auto slice_wrapper1 = cabSliceFactory.makeSliceCab<1>();
auto slice_wrapper2 = cabSliceFactory.makeSliceCab<2>();
auto slice_wrapper3 = cabSliceFactory.makeSliceCab<3>();

// simd_parallel_for setup
Cabana::SimdPolicy<vecLen, ExecutionSpace> simd_policy(0, num_tuples);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we eliminate the vecLen here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!


// kernel that reads and writes
auto vector_kernel = KOKKOS_LAMBDA(const int s, const int a) {
for (int i = 0; i < width; i++) {
printf("s: %d, a: %d, i: %d\n", s,a,i);
double x = 42/(s+a+1.3);
slice_wrapper.access(s,a,i) = x;
printf("value: %lf\n", slice_wrapper.access(s,a,i));
}
printf("s: %d, a: %d\n", s,a);
double x = 42/(s+a+1.3);
slice_wrapper0.access(s,a) = x;
slice_wrapper1.access(s,a) = s+a;
slice_wrapper2.access(s,a) = float(x);
slice_wrapper3.access(s,a) = 'a'+s+a;
printf("SW0 value: %lf\n", slice_wrapper0.access(s,a));
printf("SW1 value: %d\n", slice_wrapper1.access(s,a));
printf("SW2 value: %f\n", slice_wrapper2.access(s,a));
printf("SW3 value: %c\n", slice_wrapper3.access(s,a));
};

Cabana::simd_parallel_for(simd_policy, vector_kernel, "parallel_for_cabSliceFactory");
Expand Down