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

Initialize Array::m_executeOnGPU #1434

Merged
merged 7 commits into from
Oct 2, 2024
Merged
Changes from 2 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
16 changes: 14 additions & 2 deletions src/axom/core/Array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ class Array : public ArrayBase<T, DIM, Array<T, DIM, SPACE>>
this->clear();
static_cast<ArrayBase<T, DIM, Array<T, DIM, SPACE>>&>(*this) = other;
m_allocator_id = other.m_allocator_id;
m_executeOnGPU =
axom::detail::getAllocatorSpace(m_allocator_id) == MemorySpace::Device;
m_resize_ratio = other.m_resize_ratio;
setCapacity(other.capacity());
// Use fill_range to ensure that copy constructors are invoked for each element
Expand Down Expand Up @@ -328,6 +330,8 @@ class Array : public ArrayBase<T, DIM, Array<T, DIM, SPACE>>
m_capacity = other.m_capacity;
m_resize_ratio = other.m_resize_ratio;
m_allocator_id = other.m_allocator_id;
m_executeOnGPU =
axom::detail::getAllocatorSpace(m_allocator_id) == MemorySpace::Device;

other.m_data = nullptr;
other.m_num_elements = 0;
Expand Down Expand Up @@ -966,8 +970,8 @@ class Array : public ArrayBase<T, DIM, Array<T, DIM, SPACE>>
IndexType m_num_elements = 0;
IndexType m_capacity = 0;
double m_resize_ratio = DEFAULT_RESIZE_RATIO;
int m_allocator_id;
bool m_executeOnGPU;
int m_allocator_id = INVALID_ALLOCATOR_ID;
bool m_executeOnGPU {false};
Copy link
Member

Choose a reason for hiding this comment

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

Why do we use different variable initialization syntax? Do we have a convention that we follow?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not aware of a convention. Point taken though. This file is using assignment-style initialization for the other members so I'll change to that for the bool.

Copy link
Member

Choose a reason for hiding this comment

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

@publixsubfan -- I think in the past, you had a reason to prefer the curly brace initialization syntax. Do you recall what it was?

Once this is resolved, it might be good to update our coding conventions w/ a preference. At the very least, we should be consistent w/in a single file.

};

/// \brief Helper alias for multi-component arrays
Expand All @@ -982,6 +986,8 @@ using MCArray = Array<T, 2>;
template <typename T, int DIM, MemorySpace SPACE>
Array<T, DIM, SPACE>::Array()
: m_allocator_id(axom::detail::getAllocatorID<SPACE>())
, m_executeOnGPU(axom::detail::getAllocatorSpace(m_allocator_id) ==
MemorySpace::Device)
{ }

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -1164,6 +1170,8 @@ Array<T, DIM, SPACE>::Array(Array&& other) noexcept
m_capacity = other.m_capacity;
m_resize_ratio = other.m_resize_ratio;
m_allocator_id = other.m_allocator_id;
m_executeOnGPU =
axom::detail::getAllocatorSpace(m_allocator_id) == MemorySpace::Device;

other.m_data = nullptr;
other.m_num_elements = 0;
Expand Down Expand Up @@ -1585,6 +1593,8 @@ inline void Array<T, DIM, SPACE>::initialize(IndexType num_elements,
capacity = (num_elements > MIN_DEFAULT_CAPACITY) ? num_elements
: MIN_DEFAULT_CAPACITY;
}
m_executeOnGPU =
axom::detail::getAllocatorSpace(m_allocator_id) == MemorySpace::Device;
setCapacity(capacity);
if(default_construct)
{
Expand Down Expand Up @@ -1620,6 +1630,8 @@ inline void Array<T, DIM, SPACE>::initialize_from_other(
#endif
m_allocator_id = axom::detail::getAllocatorID<SPACE>();
}
m_executeOnGPU =
axom::detail::getAllocatorSpace(m_allocator_id) == MemorySpace::Device;
this->setCapacity(num_elements);
// Use fill_range to ensure that copy constructors are invoked for each
// element.
Expand Down
Loading