You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Possible missing sanity check in bli_determine_blocksize_b_sub() #148
In bli_determine_blocksize_b_sub() - from frame/base/bli_blksz.c:285, I think a sanity check should be added for the case dim_left_now == 0. The reason is as follow :
dim_t bli_determine_blocksize_b_sub(....)
{
// Compute how much of the matrix dimension is left, including the
// chunk that will correspond to the blocksize we are computing now.
dim_left_now = dim - i;
// Sanity check : if dim_left_now is zero then return zero without
// going any further.
// For bli_determine_blocksize_f_sub(), this check was somehow luckily done
// by comparing to b_max. Here, since we intelligently return b_alg if
// dim_left_now multiple of b_alg, we must take care of the case where
// dim_left_now is zero, because zero modulo anything is zero.
if ( dim_left_now == 0 )
return 0;
dim_at_edge = dim_left_now % b_alg;
// If dim_left_now is a multiple of b_alg, we can safely return b_alg
// without going any further.
if ( dim_at_edge == 0 )
return b_alg;
@hominhquan Can you give an example of when this sanity check would be needed? The only case I can think of in which it would apply is if computation is performed on a matrix where the initial dimension being partitioned is equal to zero. (But this situation should actually be handled by higher-level code, so the sanity check would never be used there either.)
@fgvanzee it depends what the assumptions and invariants of the function are. For example, it would seem reasonable to assume that i+(return value) <= dim which is currently violated. A different use of this function without the higher-level checking would then fail.
I would suggest (as a longer-term robustness plan) to document these assumptions and invariants through assertions (a la what @hominhquan has suggested) and through unit tests.
@devinamatthews Could you elaborate on why one would assume i+(return value) <= dim to be a reasonable invariant for this blocksize-returning function?
EDIT: Nevermind. I misread the inequality. But, could you explain why it is violated?
@fgvanzee Devin pointed out the problem. In fact, I'm using this function to determine the block size for the iteration n+1 while computing iteration n :
next_b_alg = bli_determine_blocksize( direct, i+b_alg, my_end, a,
bli_cntl_bszid( cntl ), cntx );
if ( next_b_alg > 0 ) { do some stuff here, like prefetch next block ... }
And in this case, the sanity check ensures that : if I'm computing the last block (n), so I will get zero for the next block size (n+1), because the iteration n+1 does not even exist (thanks to the for loop of the invariant) and I should stop prefetching data here.
EDIT : with the for-loop of the invariant function, the runtime only knows it has reached the end when it comes back to the for-loop and re-evaluates the condition. However, a code which wants to prefetch data for the next iteration should be pre-aware of this, to make a decision to prefetch data or not.
On August 4, 2017 1:33:54 PM PDT, "Field G. Van Zee" ***@***.***> wrote:
@devinamatthews Could you elaborate on why one would assume `i+(return
value) <= dim` to be a reasonable invariant for this
blocksize-returning function?
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#148 (comment)
On August 4, 2017 1:33:54 PM PDT, "Field G. Van Zee" ***@***.***> wrote:
@devinamatthews Could you elaborate on why one would assume `i+(return
value) <= dim` to be a reasonable invariant for this
blocksize-returning function?
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#148 (comment)
@devinamatthews@hominhquan For some reason, I completely missed that you wanted the function to return 0 when i == dim. If so, I see how it is violated now: the function continues to return b_alg.
@hominhquan I agree that your proposed special case handling is beneficial.
Activity
fgvanzee commentedon Aug 4, 2017
@hominhquan Can you give an example of when this sanity check would be needed? The only case I can think of in which it would apply is if computation is performed on a matrix where the initial dimension being partitioned is equal to zero. (But this situation should actually be handled by higher-level code, so the sanity check would never be used there either.)
devinamatthews commentedon Aug 4, 2017
@fgvanzee it depends what the assumptions and invariants of the function are. For example, it would seem reasonable to assume that
i+(return value) <= dimwhich is currently violated. A different use of this function without the higher-level checking would then fail.I would suggest (as a longer-term robustness plan) to document these assumptions and invariants through assertions (a la what @hominhquan has suggested) and through unit tests.
fgvanzee commentedon Aug 4, 2017
@devinamatthews Could you elaborate on why one would assume
i+(return value) <= dimto be a reasonable invariant for this blocksize-returning function?EDIT: Nevermind. I misread the inequality. But, could you explain why it is violated?
hominhquan commentedon Aug 4, 2017
@fgvanzee Devin pointed out the problem. In fact, I'm using this function to determine the block size for the iteration n+1 while computing iteration n :
And in this case, the sanity check ensures that : if I'm computing the last block (n), so I will get zero for the next block size (n+1), because the iteration n+1 does not even exist (thanks to the for loop of the invariant) and I should stop prefetching data here.
EDIT : with the for-loop of the invariant function, the runtime only knows it has reached the end when it comes back to the for-loop and re-evaluates the condition. However, a code which wants to prefetch data for the next iteration should be pre-aware of this, to make a decision to prefetch data or not.
devinamatthews commentedon Aug 4, 2017
devinamatthews commentedon Aug 4, 2017
fgvanzee commentedon Aug 4, 2017
@devinamatthews @hominhquan For some reason, I completely missed that you wanted the function to return 0 when
i == dim. If so, I see how it is violated now: the function continues to returnb_alg.@hominhquan I agree that your proposed special case handling is beneficial.
fgvanzee commentedon Aug 5, 2017
@hominhquan I've applied your suggested patch in 60a1eeb. Thanks for your feedback.
hominhquan commentedon Aug 6, 2017
@fgvanzee With pleasure.
Derive TRSM ref kernels from TRSM blkzsz instead of GEMM blszs (flame…