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] Plug in the SNodeRep structs into codegen #1480

Merged
merged 2 commits into from
Jul 23, 2020
Merged

Conversation

k-ye
Copy link
Member

@k-ye k-ye commented Jul 12, 2020

This is mostly a refactoring of the SNode structs implementation on Metal, with no functional changes.

I added a SNodeRep_* for each snode type supported on Metal. It is very similar to the node_* files in https://github.com/taichi-dev/taichi/tree/master/taichi/runtime/llvm. Each generated SNode structs will own an rep_ object. These SNodeRep_* provides the interfaces for operations like checking activation, activating/deactivating and getting a child.

Advantages:

  • SNodeReps make it much easier to implement listgen and struct-for kernels fo checking activation.
  • For SNodeOpStmt, before this PR, we had to manually figure out the memory address of the specific cell, then call the global helper function. Now that these functions are implemented inside each rep, we can just call the corresponding interface on the generated SNode structs themselves.

The constructor of a generated SNode takes in, in addition to its memory address, Runtime and MemoryAllocator now. These aren't used for now, but will be for pointer SNodes.

Here's an example:

class S1_ch {
 public:
  S1_ch(device byte *a) : addr_(a) {}
  S2 get0(device Runtime *rtm, device MemoryAllocator *ma) {
    return {addr_ + (0), rtm, ma};
  }

  device byte *addr() { return addr_; }

  constant static constexpr int stride = 0 + S2::stride;
 private:
  device byte *addr_;
};

struct S1 {
  // bitmasked
  constant static constexpr int n = 128;
  constant static constexpr int elem_stride = S1_ch::stride;
  constant static constexpr int stride = elem_stride * n + /*bitmasked=*/16;

  S1(device byte *addr, device Runtime *rtm, device MemoryAllocator *ma) {
    rep_.init(addr, /*meta_offset=*/elem_stride * n);
  }

  S1_ch children(int i) {
    return {rep_.addr() + (i * elem_stride)};
  }

  inline bool is_active(int i) {
    return rep_.is_active(i);
  }

  inline void activate(int i) {
    rep_.activate(i);
  }

  inline void deactivate(int i) {
    rep_.deactivate(i);
  }

 private:
  SNodeRep_bitmasked rep_;
};

Related issue = #1174

[Click here for the format server]


@k-ye k-ye marked this pull request as draft July 12, 2020 13:10
k-ye added a commit to k-ye/taichi that referenced this pull request Jul 12, 2020
@codecov
Copy link

codecov bot commented Jul 12, 2020

Codecov Report

Merging #1480 into master will increase coverage by 1.20%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1480      +/-   ##
==========================================
+ Coverage   66.17%   67.38%   +1.20%     
==========================================
  Files          38       38              
  Lines        5405     5593     +188     
  Branches      976      976              
==========================================
+ Hits         3577     3769     +192     
+ Misses       1660     1658       -2     
+ Partials      168      166       -2     
Impacted Files Coverage Δ
python/taichi/lang/__init__.py 80.92% <100.00%> (+1.08%) ⬆️
python/taichi/lang/kernel.py 81.57% <0.00%> (+0.07%) ⬆️
python/taichi/lang/impl.py 90.60% <0.00%> (+0.29%) ⬆️
python/taichi/misc/util.py 44.58% <0.00%> (+0.35%) ⬆️
python/taichi/lang/snode.py 93.69% <0.00%> (+0.36%) ⬆️
python/taichi/lang/util.py 62.26% <0.00%> (+0.48%) ⬆️
python/taichi/lang/transformer.py 93.50% <0.00%> (+0.48%) ⬆️
python/taichi/lang/meta.py 64.70% <0.00%> (+0.52%) ⬆️
python/taichi/lang/linalg.py 90.00% <0.00%> (+0.66%) ⬆️
python/taichi/lang/matrix.py 91.50% <0.00%> (+0.75%) ⬆️
... and 7 more

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 a6575fb...2147d38. Read the comment docs.

k-ye added a commit to k-ye/taichi that referenced this pull request Jul 14, 2020
@k-ye k-ye force-pushed the nmref1 branch 6 times, most recently from e251736 to 8aa6c04 Compare July 18, 2020 01:50
@k-ye k-ye force-pushed the nmref1 branch 2 times, most recently from 6c1138d to 542e341 Compare July 18, 2020 08:11
@k-ye k-ye changed the title [metal] [refactor] Introduce SNodeRep_* in the generated SNode structs [metal] Plug in the SNodeRep structs into codege Jul 18, 2020
@yuanming-hu yuanming-hu mentioned this pull request Jul 18, 2020
@k-ye k-ye changed the title [metal] Plug in the SNodeRep structs into codege [metal] Plug in the SNodeRep structs into codegen Jul 19, 2020
@k-ye k-ye marked this pull request as ready for review July 19, 2020 02:34
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.

Looks great! Thank you!

@k-ye k-ye merged commit 4cdf5f1 into taichi-dev:master Jul 23, 2020
@k-ye k-ye deleted the nmref1 branch July 23, 2020 03:41
@yuanming-hu yuanming-hu mentioned this pull request Jul 25, 2020
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.

3 participants