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

btas::group does not seem working for TensorView #48

Open
shiozaki opened this issue Jun 26, 2014 · 4 comments
Open

btas::group does not seem working for TensorView #48

shiozaki opened this issue Jun 26, 2014 · 4 comments

Comments

@shiozaki
Copy link
Contributor

I hit a bug that most likely originates from a bug in btas::group for TensorView. Here is my code. @emstoudenmire Do you have any ideas?

// slowest index of o is fixed to n
shared_ptr<Matrix> DFBlock::form_4index_1fixed(const shared_ptr<const DFBlock> o, const double a, const size_t n) const {
 if (asize() != o->asize()) throw logic_error("illegal call of DFBlock::form_4index_1fixed");
 auto target = make_shared<Matrix>(b2size()*b1size(), o->b1size());
#if 0
 auto low = {0, 0, int(n)};
 auto up  = {int(o->asize()), int(o->b1size()), int(n+1)}; 
 TensorView3<double> ov(o->range().slice(low, up), o->storage());
 contract(a, group(*this,1,3), {1,0}, group(ov,1,3), {1,2}, 0.0, *target, {0,2});
#else
 dgemm_("T", "N", b1size()*b2size(), o->b1size(), asize(), a, data(), asize(), o->data()+n*asize()*o->b1size(), asize(), 0.0, target->data(), b1size()*b2size());
#endif
 return target;
}
@emstoudenmire
Copy link
Contributor

Hi Toru, I'd be happy to look into this. Could you tell me what the rank and index extents of the two tensors passed to group(...,1,3) were for the case(s) that failed?

@shiozaki
Copy link
Contributor Author

The rank is both 3, and the extents are both (95, 4, 14) in which 95 runs fastest. I am making a slice of (95,4,1) of one of them (with column being specified by the function argument), and call contract between two Tensor2 to produce Tensor 2 of extent (4*14, 4).
The tensors are defined as

 41   template<int N>
 42   using CRange = RangeNd<CblasColMajor>;
 48   template<typename T>
 49   using Tensor3 = Tensor<T, CRange<3>, bagel::varray<T>>;
 57   template<typename T>
 58   using TensorView3 = TensorView<T, CRange<3>, bagel::varray<T>>;

I know that btas::group is working for Tensor3, and that contract has been verified for Tensor2 times Tensor2 (since I am using it a lot). bagel::varray is basically btas::varray that has the capacity information.

I may as well be my bug, so if you find something strange, just let me know.

@emstoudenmire
Copy link
Contributor

Hi Toru, was the bug you were seeing a runtime bug? I am finding that calling contract with TensorView arguments does not compile, and the reason seems pretty deeply "baked in" to the logic of contract at the moment. Specifically, inside contract in many cases the "A" and "B" tensors are permuted / reshaped into new temporary tensors which are instantiated as objects of the same type (_TensorA and _TensorB types, respectively). If one of these types is a TensorView then the resulting object doesn't allocate its own storage and can't be used to hold the permuted data.

It's not clear to me the best way to proceed. Maybe contract should permute (reshape) the data into a temporary of type _TensorA::storage_type instead of type _TensorA itself.

@shiozaki
Copy link
Contributor Author

Hi Miles, it was a runtime bug, because I used my own version of contract that is in btas/optimize/contract.h. This version does not involve permute (these codes are not general enough, so it is not defaulted), and my slice was contiguous. I am not sure either how we should proceed with permute.

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

2 participants