-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7761635
commit 3e5a42b
Showing
6 changed files
with
85 additions
and
5 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
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,76 @@ | ||
diff --git a/general/workspace.cpp b/general/workspace.cpp | ||
index ad8210a61..69622ec70 100644 | ||
--- a/general/workspace.cpp | ||
+++ b/general/workspace.cpp | ||
@@ -15,11 +15,11 @@ namespace mfem | ||
{ | ||
|
||
WorkspaceVector::WorkspaceVector( | ||
- internal::WorkspaceChunk &chunk_, int offset_, int n) | ||
+ internal::WorkspaceChunk &chunk_, int offset_, int n, int padding) | ||
: Vector(chunk_.GetData(), chunk_.GetOffset(), n), | ||
chunk(chunk_), | ||
offset(offset_), | ||
- original_size(n) | ||
+ original_size(n + padding) | ||
{ | ||
UseDevice(true); | ||
} | ||
@@ -47,9 +47,12 @@ WorkspaceChunk::WorkspaceChunk(int capacity) | ||
|
||
WorkspaceVector WorkspaceChunk::NewVector(int n) | ||
{ | ||
- MFEM_ASSERT(HasCapacityFor(n), "Requested vector is too large."); | ||
- WorkspaceVector vector(*this, offset, n); | ||
- offset += n; | ||
+ constexpr int alignment = 16; | ||
+ const int s = (n * sizeof(double)) % alignment; | ||
+ const int padding = (s > 0) ? (alignment - s) / sizeof(double) : 0; | ||
+ MFEM_ASSERT(HasCapacityFor(n + padding), "Requested vector is too large."); | ||
+ WorkspaceVector vector(*this, offset, n, padding); | ||
+ offset += n + padding; | ||
vector_count += 1; | ||
return vector; | ||
} | ||
diff --git a/general/workspace.hpp b/general/workspace.hpp | ||
index b5c0ebae8..e41e71b11 100644 | ||
--- a/general/workspace.hpp | ||
+++ b/general/workspace.hpp | ||
@@ -50,7 +50,8 @@ class WorkspaceVector : public Vector | ||
bool moved_from = false; | ||
|
||
/// Private constructor, create with Workspace::NewVector() instead. | ||
- WorkspaceVector(internal::WorkspaceChunk &chunk_, int offset_, int n); | ||
+ WorkspaceVector(internal::WorkspaceChunk &chunk_, int offset_, int n, | ||
+ int padding = 0); | ||
|
||
public: | ||
/// @brief Move constructor. The moved-from WorkspaceVector has @a | ||
@@ -104,6 +105,9 @@ public: | ||
/// Create a WorkspaceChunk with the given @a capacity. | ||
WorkspaceChunk(int capacity); | ||
|
||
+ /// Return the data offset. | ||
+ int GetOffset() const { return offset; } | ||
+ | ||
/// @brief Return the available capacity (i.e. the largest vector that will | ||
/// fit in this chunk). | ||
int GetAvailableCapacity() const { return data.Size() - offset; } | ||
@@ -115,15 +119,12 @@ public: | ||
/// "original capacity" remains unchained. | ||
int GetOriginalCapacity() const { return original_capacity; } | ||
|
||
- /// Return the data offset. | ||
- int GetOffset() const { return offset; } | ||
+ /// Returns true if this chunk can fit a new vector of size @a n. | ||
+ bool HasCapacityFor(int n) const { return n <= GetAvailableCapacity(); } | ||
|
||
/// Sets whether the chunk is in the front of the list | ||
void SetFront(bool front_) { front = front_; } | ||
|
||
- /// Returns true if this chunk can fit a new vector of size @a n. | ||
- bool HasCapacityFor(int n) const { return n <= GetAvailableCapacity(); } | ||
- | ||
/// Returns true if this chunk is empty. | ||
bool IsEmpty() const { return vector_count == 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
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