[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fftw and memory alignment

From: Paul Kienzle
Subject: fftw and memory alignment
Date: Tue, 17 Feb 2004 10:03:14 -0500
User-agent: Mutt/


Regarding aligned memory, I did some searching in Blitz++.

You can see the code on source-forge:


The guts of the allocator are in memblock.cc.  

The idea is what you would expect: allocate a hunk one 
block size bigger than you need, then use the mod function 
to find an offset within that block.  You need to keep track 
of the original pointer so you can free it later.  

For pointer arithmetic, they are using ptrdiff_t from stddef.h:

  const int cacheBlockSize = 128;    // Will work for 32, 16 also
  dataBlockAddress_ = reinterpret_cast<T_type*>
      (new char[numBytes + cacheBlockSize - 1]);

  // Shift to the next cache line boundary
  ptrdiff_t offset = ptrdiff_t(dataBlockAddress_) % cacheBlockSize;
  int shift = (offset == 0) ? 0 : (cacheBlockSize - offset);
  data_ = (T_type*)(((char *)dataBlockAddress_) + shift);

They are only aligning large blocks, not small ones.  I don't
know what affect that will have on fftw.  If it is unaligned
does the algorithm collapse?  Or is it just slower?  Or does
it require more code and wisdom to support?

There are complications with constructors/destructors. If 
they exist for the type you are allocating, then you need 
to explicitly run the constructor/destructor for each element.

Paul Kienzle

reply via email to

[Prev in Thread] Current Thread [Next in Thread]