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

[Lang] MatrixNdarray refactor part2: Remove redundant members in python-scope AnyArray #5885

Merged
merged 23 commits into from
Aug 30, 2022

Conversation

jim19930609
Copy link
Contributor

@jim19930609 jim19930609 commented Aug 26, 2022

Related issue = #5873, #5819

This PR belongs to "Part ②" in #5873.

After this PR, [Python]AnyArray only keeps a ptr to an underlying C++ object ExternalTensorExpression. AnyArray's attributes such as shape and layout should be directly fetched from self.ptr, so that they stay in sync with ExternalTensorExpression all the time.

@netlify
Copy link

netlify bot commented Aug 26, 2022

Deploy Preview for docsite-preview ready!

Name Link
🔨 Latest commit 73d3fce
🔍 Latest deploy log https://app.netlify.com/sites/docsite-preview/deploys/630c81b0de6fed0008973df3
😎 Deploy Preview https://deploy-preview-5885--docsite-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@jim19930609 jim19930609 requested review from ailzhang and strongoier and removed request for ailzhang August 29, 2022 10:56
@jim19930609 jim19930609 requested review from ailzhang, strongoier, k-ye and AD1024 and removed request for strongoier and ailzhang August 29, 2022 10:56
Copy link
Contributor

@strongoier strongoier left a comment

Choose a reason for hiding this comment

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

LGTM!

@jim19930609 jim19930609 merged commit 804e713 into taichi-dev:master Aug 30, 2022
@@ -14,17 +14,26 @@ class AnyArray:
element_shape (Tuple[Int]): () if scalar elements (default), (n) if vector elements, and (n, m) if matrix elements.
layout (Layout): Memory layout.
"""
def __init__(self, ptr, element_shape, layout):
def __init__(self, ptr):
assert ptr.is_external_var()
self.ptr = ptr
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it's easier to set self.element_shape & self.layout directly here. I can understand that we want to keep element_shape/layout in sync with the ptr but querying into C++ from python is also kinda expensive. So maybe we can add an assumption here (not using facing IIUC) and save some perf in small kernel cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that sounds more like a caching mechanism, where we cache a bunch of C++ values at Python scope to minimize pybind performance loss. If we want to minimize the logics in Frontend language, then we'll need this cache sooner or later.

IMO, the self.element_shape and self.layout are essentially ill-implemented caches which easily causes mismatch between Python and C++ objects. Moreover, this cache also got no centralized management, and can spread all over the code base.

Maybe we can implement a better caching mechanism together with "pybind - ctypes" refactor?

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