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

[metal] Add SNodeRep_pointer #2000

Merged
merged 1 commit into from
Oct 28, 2020
Merged

Conversation

k-ye
Copy link
Member

@k-ye k-ye commented Oct 26, 2020

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 an int32_t that indexes into somewhere in the Metal buffer memory. The NodeManager instance passed to this Rep's init() knows how to recover the data address from this int32_t. See child_or_ambient_addr().

  • In [metal] Refactor sparse shader impl in prep for pointer SNode #1994, I added NodeManager::ElemIndex, which has a notion of raw vs index value. They differ by kIndexOffset.

    inline int32_t index() const {
    return raw_ - kIndexOffset;
    }
    inline int32_t raw() const {
    return raw_;
    }
    inline bool is_valid() const {
    return raw_ >= kIndexOffset;
    }

    This shift is necessary for ElemIndex to know if its raw_ is a valid index in the memory or not. A valid raw_ value is always greater than or equal to kIndexOffset, 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 its ElemIndex, which is initialized to 0. Inside activate(), if the allocation succeeds, it will store nm_idx_raw = nm_.allocate().raw() into the cell. As a result, in to_nodemgr_idx(), we read the cell's int32_t, and uses ElemIndex::from_raw(), instead of ElemIndex::from_index(). Same for deactivate().

Related issue = #1740

[Click here for the format server]


@codecov
Copy link

codecov bot commented Oct 26, 2020

Codecov Report

Merging #2000 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2000   +/-   ##
=======================================
  Coverage   43.50%   43.50%           
=======================================
  Files          45       45           
  Lines        6266     6266           
  Branches     1109     1109           
=======================================
  Hits         2726     2726           
  Misses       3367     3367           
  Partials      173      173           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 16af509...e939071. Read the comment docs.

Copy link
Member

@yuanming-hu yuanming-hu left a comment

Choose a reason for hiding this comment

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

LGTM!

Just curious: it seems that Metal doesn't support 64-bit data types, but there are indeed pointers in the code. Are all pointers 32-bit in Metal?

@yuanming-hu yuanming-hu merged commit 9b2b25f into taichi-dev:master Oct 28, 2020
@k-ye
Copy link
Member Author

k-ye commented Oct 28, 2020

Just curious: it seems that Metal doesn't support 64-bit data types, but there are indeed pointers in the code. Are all pointers 32-bit in Metal?

I believe the pointers are still 64bit, we just don't have 64bit data support (at least not in the Metal buffer :-/ )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants