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

Overflow bug in boolean tensor views #100

Closed
romeric opened this issue Jun 4, 2020 · 2 comments
Closed

Overflow bug in boolean tensor views #100

romeric opened this issue Jun 4, 2020 · 2 comments

Comments

@romeric
Copy link
Owner

romeric commented Jun 4, 2020

The following example illustrates the issue

constexpr seq sall = seq(0,-1,1);
Tensor<float,4,4> a; a.iota(5);
Tensor<bool,4,4> ba5;
ba5(sall,sall) = a == a;

This is because in operator=(const AbstractTensor<Derived,2> &a) of the tensor view the eval from the right hand size expression generates a boolean simd vector of 4 (under SSE) SIMDVector<boo,simd_abi::fixed<4>> but the simd vector of the left hand side (the view itself) is constructed at the time of construction of the view when the incoming rhs is not known of course and this is SIMDVector<bool,simd_abi::scalar>. As a result the loop calls the rhs 4x4=16 times (in a scalar) fashion and rhs as a result being a SIMDVector<boo,simd_abi::fixed<4>> accesses 4 items ahead and hence the memory is accessed beyond it's bounds.

To be consistent we need to implemented the same strategy as its implemented in Tensor constructors that is

FASTOR_IF_CONSTEXPR(is_boolean_expression_v<Derived>) { 
    // do sequential access
}

Of course till SIMDMask is implemented.

@romeric
Copy link
Owner Author

romeric commented Jun 4, 2020

Fixed here a05e4a0 for all views excluding random views I guess. Fiter and Diag views don't use vectorisation.

@romeric
Copy link
Owner Author

romeric commented Jun 4, 2020

This temporarily fixes the issue so closing for now till #54 is implemented.

@romeric romeric closed this as completed Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant