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

Refactor Storage with templates #469

Draft
wants to merge 9 commits into
base: dev-master
Choose a base branch
from
Draft

Conversation

IvanaGyro
Copy link
Collaborator

Try to refactor Storage with templates to reduce duplicated code and prevent low-level memory management.

Too many files include `utils_internal_interface.hpp`, but don't use the
symbols directly declared in `utils_internal_interface.hpp`. This causes
the build system to unnecessarily compile almost the whole project when
a file included by `utils_internal_interface.hpp` is modified. Following
the [Include What You Use](https://google.github.io/styleguide/cppguide.html#Include_What_You_Use)
the rule can reduce the probability of circular including and the
building time.
Follow the "Include What You Use" rule.
`to_(device)` will be removed.
Fix typo in tests/gpu/BlockUniTensor_test.cpp
@kaihsin
Copy link
Member

kaihsin commented Sep 14, 2024

Make sure you staging the progress into multiple PRs instead of making a big one for all modification. Other than that LGTM so far

@kaihsin
Copy link
Member

kaihsin commented Sep 14, 2024

@IvanaGyro Let me know if you hit a point where the refactor is ready. I want to start moving Storage + Tensor into another repo
cytnx-core

@IvanaGyro
Copy link
Collaborator Author

IvanaGyro commented Sep 14, 2024

I suggest deciding whether to move Storage and Tensor after the refactoring process. Currently, only three files (excluding CUDA kernels) remain for Storage. Furthermore, we can combine Tensor with Tensor_Impl and merge Storage with Storage_base, provided we maintain the current API and ensure high memory efficiency. If we also consider replacing Storage with thrust::vector, there will only be two classes beneath Tensor. If there are only a few files below the Tensor level, keeping those files in the same repository could simplify maintenance.

@kaihsin
Copy link
Member

kaihsin commented Sep 14, 2024 via email

@IvanaGyro
Copy link
Collaborator Author

IvanaGyro commented Sep 15, 2024

It's fine to leave Tensor and Storage as abstract classes apart from their implementation.

I wonder what are the reasons for splitting the repo? What are the plans for maintaining the dependencies in the linear algebra components, CUDA kernel, and the other high-level components?

@kaihsin
Copy link
Member

kaihsin commented Sep 15, 2024

It's fine to leave Tensor and Storage as abstract classes apart from their implementation.

I wonder what are the reasons for splitting the repo? What are the plans for maintaining the dependencies in the linear algebra components, CUDA kernel, and the other high-level components?

The plan is to separate UniTensor from the underlying Tensor, so other ppl can use Tensor and also bridge torch.Tensor, xtensor, jax and numpy directly.

@kaihsin
Copy link
Member

kaihsin commented Sep 15, 2024

All GPU, CUDA kernels for Tensor (and below) should go to cytnx-core

@kaihsin
Copy link
Member

kaihsin commented Sep 15, 2024

It's fine to leave Tensor and Storage as abstract classes apart from their implementation.

I wonder what are the reasons for splitting the repo? What are the plans for maintaining the dependencies in the linear algebra components, CUDA kernel, and the other high-level components?

Its more like a wrapper than the abstract class. Storage_base/ Tensor_impl was supposed to be the abstract class, and Tensor/Storage is the wrapper for C++ API

@yingjerkao
Copy link
Collaborator

It's fine to leave Tensor and Storage as abstract classes apart from their implementation.
I wonder what are the reasons for splitting the repo? What are the plans for maintaining the dependencies in the linear algebra components, CUDA kernel, and the other high-level components?

Its more like a wrapper than the abstract class. Storage_base/ Tensor_impl was supposed to be the abstract class, and Tensor/Storage is the wrapper for C++ API

In light of this, I wonder if there is a class diagram explaining all these somewhere? It should be included in the developer's manual

@kaihsin
Copy link
Member

kaihsin commented Sep 15, 2024

I would love to chat with @IvanaGyro and ppl who are involved on this. I feel like it would be nice to have a conversation on why it was design in that way, what was the concern, and maybe there are better way to fulfill them.

A few convo among the issues makes me think we are not on the same page, and I think it is also hard for @IvanaGyro to work on stuffs when lacking informations

@yingjerkao
Copy link
Collaborator

Still it would be nice to have some documentation. At some point I understood the design but I don't recall all the details.

@kaihsin
Copy link
Member

kaihsin commented Sep 15, 2024

I suggest we have a meeting and maybe someone can take a note?

@ianmccul
Copy link

ianmccul commented Sep 15, 2024

dtype and device would be better implemented using std::variant. That way, the enumeration of all of the possible types and devices only needs to happen once. That would turn a lot of runtime errors (such as missing some function for a specific dtype or device) into compile time errors, and much easier to maintain. Single or multiple dispatch is really easy with std::variant and visitors. With the current design, adding a new dtype would be a major hassle, and no way to check that all of the required functions are supplied without runtime testing.

Also, for the C++ code, is there a reason for restricting the types of a Tensor to a specific set? For Python it is obviously required that it is a bounded set, but C++ code could be able to construct a Tensor on any type. Eg, if I wanted to experiment with some Tensor<float128>, or Tensor<BigFloat>?

Edit: github ate my formatting!

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.

4 participants