Skip to content

Mismatch between logic and code in frame/3/bli_l3_packm.c:123 #147

Closed

Description

@hominhquan

I noticed a mismatch between algorithmic comments and the if condition in frame/3/bli_l3_packm.c:123 :

  // If the mem_t entry in the control tree does NOT contain a NULL            
  // buffer, then a block has already been acquired from the memory            
  // broker and cached in the control tree.                                    
                                                                               
  // BUT, we need to make sure that the mem_t object is not associated         
  // with a block that is too small given the size of the packed matrix        
  // that we need, according to the return value from packm_init().            
  siz_t cntl_mem_size = bli_mem_size( cntl_mem_p );

  if ( size_needed < cntl_mem_size ) ....

Instead, it should be :

  if ( size_needed > cntl_mem_size )  .... 

to correspond to the behavior described in its following code (between releasing the smaller block and acquire a new one, or use it as-is)

Note : If this is effectively a minor typing error, I wonder how has this not been seen before and dit not break any test ? especially with TRSM in BACKWARD order, where the block size is increasing from small to big ..?

Activity

  1. fgvanzee commented on Aug 4, 2017

    @fgvanzee
    Member

    @hominhquan Thank you for pointing this out. This does appear to be a bug--one that would manifest in the form of unnecessary memory release and re-allocation from the memory broker. Thankfully, it is only a performance bug and does not appear to affect the computational output.

    I can understand why you might be concerned about backwards-moving trsm. There, the bottom-right edge case is handled first, and then all subsequent blocks would be regular-sized. But here is why it never resulted in problems: the size of the mem_t entries is always their allocated size, even if the mem_t was acquired with a smaller requested size. This means that the runtime behavior fits into the overall pattern of the other operations, which is that blocks are simply released and re-allocated for every iteration (except the first time, before a mem_t entry is cached).

    EDIT: I just want to add that, given the current mechanism in place for BLIS's internal packed memory allocation, the erroneous conditional is really meant to be a sanity check and nothing more. If BLIS ever moved to a system where packed memory was allocated via malloc() instead of from a pre-allocated memory pool, then the sanity check would be required. As of now, I think we could remove that block of code if we really wanted to. But I think it is wise to leave it in for the aforementioned reason.

  2. fgvanzee commented on Aug 4, 2017

    @fgvanzee
    Member

    This should be fixed in b01c808. Thanks again, Minh.

  3. hominhquan commented on Aug 4, 2017

    @hominhquan
    ContributorAuthor

    @fgvanzee OK, I get it now why it is just a performance-bug. Also, I understand that the if-condition is simply a sanity check of the "recycling" mechanism through internal pool. Thus, for me, it is of course necessary to be here.

  4. devinamatthews commented on Aug 4, 2017

    @devinamatthews
    Member

    @hominhquan also note that it would be a bug if the memory pool blocks were allocated dynamically based on requested size. For example, this is what I do in TBLIS and this code would definitely fail there.

  5. fgvanzee commented on Aug 4, 2017

    @fgvanzee
    Member

    @devinamatthews Agreed. Kind of ironic that the sanity check is the thing that would have caused the error. #sanityfail

  6. hominhquan commented on Aug 4, 2017

    @hominhquan
    ContributorAuthor

    @devinamatthews Do you mean that this is also the hidden bug in TBLIS which always gives false results ? If this is the case, it is a good news, because, effectively, I identified this bug by doing dynamic allocation with GEN_USE buffers.

  7. fgvanzee commented on Aug 4, 2017

    @fgvanzee
    Member

    @hominhquan I think that by "this is what I do in TBLIS," Devin was referring to dynamic allocation based on the requested size.

  8. devinamatthews commented on Aug 4, 2017

    @devinamatthews
    Member
  9. hominhquan commented on Aug 4, 2017

    @hominhquan
    ContributorAuthor

    OK, so it means that this bug only pop-up when one is doing dynamic allocation on requested size.

  10. fgvanzee commented on Aug 4, 2017

    @fgvanzee
    Member

    @hominhquan Correct. And so that would only affect people who had hacked out the internal memory pools and replaced them with malloc() or some equivalent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions