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

Update Tape.h issue #793 #1

Merged
merged 1 commit into from
Mar 21, 2024
Merged
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
21 changes: 12 additions & 9 deletions include/clad/Differentiator/Tape.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,25 @@ namespace clad {
}
}
/// Initial capacity (allocated whenever a value is pushed into empty tape).
constexpr static std::size_t _init_capacity = 32;
CUDA_HOST_DEVICE void grow() {
// If empty, use initial capacity.
if (!_capacity)
constexpr static std::size_t _init_capacity = 32;
CUDA_HOST_DEVICE void grow() {
// If empty, use initial capacity.
if (!_capacity)
_capacity = _init_capacity;
else
else
// Double the capacity on each reallocation.
_capacity *= 2;
T* new_data = AllocateRawStorage(_capacity);

if (!new_data) {
// clean up the memory mess just in case!
T* new_data = AllocateRawStorage(_capacity);

if (!new_data) {
// Clean up the memory mess just in case!
destroy(begin(), end());
printf("Allocation failure during tape resize! Aborting.\n");
trap(EXIT_FAILURE);
}
}
}


// Move values from old storage to the new storage. Should call move
// constructors on non-trivial types, otherwise is expected to use
Expand Down