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

Using IndexSetVar defined at runtime #553

Open
smr97 opened this issue Aug 24, 2023 · 0 comments
Open

Using IndexSetVar defined at runtime #553

smr97 opened this issue Aug 24, 2023 · 0 comments

Comments

@smr97
Copy link

smr97 commented Aug 24, 2023

Hi everyone!
I have a use-case where I want to "slice" into a high dimensional tensor at specific points in the leading dimension.
However, these points change at run-time. I see from the code that IndexSetVar is formed using an integer given to the IndexVar before the TACO code is generated (before calling .compile()). Is there a way to compile the einsum expression with a generic slice position, and run the contraction with a different value of the slice position?
Here is an example:

Tensor<double> threedee = Tensor<double>("3d", {X, Y, Z});
Tensor<double> matr = Tensor<double>("mat", {Z, A});
Tensor<double> res = Tensor<double>("res", {Y, A});
for(int x = 0; x < X; x++){
    res(y, a) = threedee(x_var({x}), y, z) * res(y, a);
    res.evaluate();
}

This is how I currently do it, but it is slow, because the TACO compilation happens for every iteration of the for loop.
I want the code to be generated just once, with an argument x, and I can pass in a different value of x each iteration of the loop. So, something like this:

Tensor<double> threedee = Tensor<double>("3d", {X, Y, Z});
Tensor<double> matr = Tensor<double>("mat", {Z, A});
Tensor<double> res = Tensor<double>("res", {Y, A});
int x = 0;
res(y, a) = threedee(x_var({x}), y, z) * res(y, a);
res.compile();
for(int iter = 0; iter < X; iter++){
    res.assemble(x = iter);
    res.compute(x = iter);
}

Maybe this is already implemented in a different way? I am not sure what's the fastest way to run this, so any help would be appreciated!!

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

No branches or pull requests

1 participant