Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • sac2c sac2c
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 403
    • Issues 403
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • Deployments
    • Deployments
    • Releases
  • Wiki
    • Wiki
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • sac-group
  • sac2csac2c
  • Issues
  • #1330
Closed
Open
Created Aug 08, 2004 by Kai Trojahner@ktrGuest

Invalid fold-funs can lead to memory leaks in EMM

Bugzilla Link 43
Created on Aug 08, 2004 14:28
Resolution FIXED
Resolved on Aug 08, 2004 15:52
Version 1.00beta
OS SunOS
Architecture Sun
Attachments leak.sac

Extended Description

In the livermore-loops examples, often the following fold function is used:
inline int[.] second( int[.] a, int[.] b) {
  return(b);
}
Using this fold function allows to abuse the fold-withloop as some kind of
iteration construct. Unfortunately this will lead to memory leak if accumulation
is made explicit.
Have a look at the following example:
inline int[.] second( int[.] a, int[.] b) {
  res = b;
  return(res);
}
int[.] f( int[.] iv, int[.] A) {
  return( A);
}
int main() {
  A = with (. <= iv <= .) genarray( [1024], 1);
  n = with (. <= iv <= .) genarray( [1024], 0);
  F = with ([0] <= iv < [10])
      fold ( second, n, f(iv,A));
  
  return( F[[0]]);
}
After b14 the fold withloop looks like this:
  F = with ( _flat_6_iv )
        (_flat_4 <= _flat_6_iv=[_type_12] < _flat_5)
        { 
          _ea_15_F = accu( _flat_6_iv); 
          _flat_7 = _MAIN:f( _flat_6_iv, A); 
          _ea_16__flat_7 = _FOLD:_type_13__MAIN__second( _ea_15_F, _flat_7); 
        } : _ea_16__flat_7 ; 
      fold/*fun*/( _FOLD:_type_13__MAIN__second, n); 
After inlining the fold function we get:
  F = with ( _flat_6_iv )
        (_flat_4 <= _flat_6_iv=[_type_12] < _flat_5)
        { 
          _ea_15_F = accu( _flat_6_iv); 
          _flat_7 = _MAIN:f( _flat_6_iv, A); 
          _inl_20__flat_7 = _flat_7; 
          _inl_19_F = _ea_15_F; 
          _inl_23_b = _inl_20__flat_7; 
          _inl_22_a = _inl_19_F; 
          _inl_21_res = _inl_23_b; 
          _inl_17__type_14_F = _inl_21_res; 
          _inl_18_F__SSA0_1 = _inl_17__type_14_F; 
          _ea_16__flat_7 = _inl_18_F__SSA0_1; 
        } : _ea_16__flat_7 ; 
      fold/*fun*/( _FOLD:_type_13__MAIN__second, n); 
And finally, after the first application of DCR we obtain:
  F = with ( _flat_6_iv )
        ([ 0 ] <= _flat_6_iv=[_type_12] < [ 10 ])
        { 
          _flat_7 = _MAIN:f( _flat_6_iv, A); 
        } : _flat_7 ; 
      fold/*fun*/( _FOLD:_type_13__MAIN__second, n); 
This seems to be a great optimization result, but unfortunately, we lost the
handle to the last intermediate fold result which was represented by accu().
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking