Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SNodeRep_pointer
is functionally equivalent to LLVM's https://github.com/taichi-dev/taichi/blob/master/taichi/runtime/llvm/node_pointer.h. There are a few implementation details specific to Metal, though:Like the LLVM backend, each cell of a
pointer
SNode stores only the pointer to the data, not the data itself. However, unlike LLVM, this is not a real pointer, but merely anint32_t
that indexes into somewhere in the Metal buffer memory. TheNodeManager
instance passed to this Rep'sinit()
knows how to recover the data address from thisint32_t
. Seechild_or_ambient_addr()
.In [metal] Refactor sparse shader impl in prep for pointer SNode #1994, I added
NodeManager::ElemIndex
, which has a notion ofraw
vsindex
value. They differ bykIndexOffset
.taichi/taichi/backends/metal/shaders/runtime_structs.metal.h
Lines 89 to 99 in 16af509
This shift is necessary for
ElemIndex
to know if itsraw_
is a valid index in the memory or not. A validraw_
value is always greater than or equal tokIndexOffset
, while values below that represents special values that are necessary for the memory allocation ([Metal] Support dynamic memory allocation on GPU #1174) to work (0
:nullptr
;1
: allocation in progress).A
pointer
SNode cell stores the raw value of itsElemIndex
, which is initialized to0
. Insideactivate()
, if the allocation succeeds, it will storenm_idx_raw = nm_.allocate().raw()
into the cell. As a result, into_nodemgr_idx()
, we read the cell'sint32_t
, and usesElemIndex::from_raw()
, instead ofElemIndex::from_index()
. Same fordeactivate()
.Related issue = #1740
[Click here for the format server]