Skip to content

Commit 8ddebc0

Browse files
liu15adayton1
andauthored
Fix set() for uninitialized managed arrays (#313)
* Fix set() for uninitialized managed arrays if the default space is not CPU --------- Co-authored-by: Alan Dayton <6393677+adayton1@users.noreply.github.com> Co-authored-by: Alan Dayton <dayton8@llnl.gov>
1 parent 8333f24 commit 8ddebc0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

RELEASE_NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ The format of this file is based on [Keep a Changelog](http://keepachangelog.com
1818
### Changed
1919
- Use memcpy instead of umpire copy for CPU-only thin managed array realloc (allows tracking to be disabled).
2020

21+
### Fixed
22+
- Fixed ManagedArray::set when CHAI\_DISABLE\_RM=OFF and the initial space is not CPU
23+
2124
## [Version 2025.03.0] - Release date 2025-03-19
2225

2326
### Added

src/chai/ManagedArray.inl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,13 @@ CHAI_HOST_DEVICE void ManagedArray<T>::set(size_t i, T val) const {
363363
#endif
364364

365365
if (m_pointer_record->m_last_space == NONE) {
366-
m_pointer_record->m_last_space = CPU;
366+
// Use the first non-null pointer if managed array was not used yet
367+
for (int s = CPU; s < NUM_EXECUTION_SPACES; ++s) {
368+
if (m_pointer_record->m_pointers[s] != nullptr) {
369+
m_pointer_record->m_last_space = static_cast<ExecutionSpace>(s);
370+
break;
371+
}
372+
}
367373
}
368374

369375
m_pointer_record->m_touched[m_pointer_record->m_last_space] = true;

0 commit comments

Comments
 (0)