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

Refactor constructField #761

Merged
merged 2 commits into from
Jan 21, 2024
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ endif()
if (MSVC)
# FIXME(bgruber): alpaka uses M_PI, so we need to make it available on MSVC. This may be fixed in alpaka 1.0.0.
target_compile_definitions(llama INTERFACE _USE_MATH_DEFINES)
target_compile_options(${PROJECT_NAME} INTERFACE /Zc:lambda) # needed in C++17 mode, remove when upgrading to C++20
endif()

# CUDA
Expand Down
31 changes: 13 additions & 18 deletions include/llama/View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,34 +98,29 @@ namespace llama
typename Mapping::ArrayExtents::Index ai,
RecordCoord<RCs...> rc)
{
using FieldType = GetType<typename Mapping::RecordDim, decltype(rc)>;

// this handles physical and computed mappings
if constexpr(sizeof...(RCs) == 0)
auto init = [](auto&& ref) LLAMA_LAMBDA_INLINE
{
using RefType = decltype(view(ai));
if constexpr(isProxyReference<RefType>)
using FieldType = GetType<typename Mapping::RecordDim, RecordCoord<RCs...>>;
using RefType = decltype(ref);
if constexpr(isProxyReference<std::remove_reference_t<RefType>>)
{
view(ai) = FieldType{};
ref = FieldType{};
}
else if constexpr(
std::is_lvalue_reference_v<RefType> && !std::is_const_v<std::remove_reference_t<RefType>>)
{
new(&view(ai)) FieldType{};
new(&ref) FieldType{};
}
};

// this handles physical and computed mappings
if constexpr(sizeof...(RCs) == 0)
{
init(view(ai));
}
else
{
using RefType = decltype(view(ai)(rc));
if constexpr(isProxyReference<RefType>)
{
view(ai)(rc) = FieldType{};
}
else if constexpr(
std::is_lvalue_reference_v<RefType> && !std::is_const_v<std::remove_reference_t<RefType>>)
{
new(&view(ai)(rc)) FieldType{};
}
init(view(ai)(rc));
}
}

Expand Down
Loading