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

[NDTensorsGPUArraysCoreExt] Fix nonuniform Diag-Dense contractions on GPU #1511

Merged
merged 15 commits into from
Jun 24, 2024

Conversation

mtfishman
Copy link
Member

@mtfishman mtfishman commented Jun 23, 2024

This fixes:

using ITensors: Index, random_itensor, diag_itensor
using Metal: mtl
device = mtl
d = 3
i, j = Index.((d, d))
a = device(random_itensor(i, j))
d = device(diag_itensor(randn(d), i, j))
a * d

whereas before that contraction failed with a scalar indexing error. The fix is fairly crude and is based on converting the Diag tensor to Dense, similar to the fix for contracting uniform Diag with Dense in #1453.

I've also added some definitions for mapreduce for Tensors with storage types Dense, Diag, and BlockSparse, and defined sum(::ITensor) and prod(::ITensor) which make use of those definitions and therefore work on GPU and take advantage of sparsity.

This fixes the issues raised in https://itensor.discourse.group/t/gpu-issues-scalar-indexing-is-disallowed-on-sum-itensor-and-traces-of-products-involving-diagonal-itensors/1828.

@codecov-commenter
Copy link

codecov-commenter commented Jun 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.21%. Comparing base (7d5ecf9) to head (c631b00).

Current head c631b00 differs from pull request most recent head c308634

Please upload reports for the commit c308634 to get more accurate results.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1511   +/-   ##
=======================================
  Coverage   79.21%   79.21%           
=======================================
  Files         148      148           
  Lines        9658     9658           
=======================================
  Hits         7651     7651           
  Misses       2007     2007           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mtfishman
Copy link
Member Author

@kmp5VT I also went ahead and started using NDTensors.map_diag! to implement the definition of that function for ITensor, as a followup to #1497.

@mtfishman
Copy link
Member Author

@kmp5VT another thing I added in this PR is a generic definition of == for Tensors which avoids scalar indexing and therefore works on GPU. I switched over some tests to use that new definition. It looks like we could remove a few @allowscalar calls in the tests now that we have that.

@kmp5VT
Copy link
Collaborator

kmp5VT commented Jun 23, 2024

@kmp5VT another thing I added in this PR is a generic definition of == for Tensors which avoids scalar indexing and therefore works on GPU. I switched over some tests to use that new definition. It looks like we could remove a few @allowscalar calls in the tests now that we have that.

This is great, thanks!!

@mtfishman mtfishman merged commit d3afdb7 into main Jun 24, 2024
14 of 15 checks passed
@mtfishman mtfishman deleted the NDTensorsGPUArraysCoreExt_contract_dense_diag branch June 24, 2024 00:23
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