[Numpy-discussion] object array alignment issues
Michael Droettboom
mdroe@stsci....
Fri Oct 16 07:31:08 CDT 2009
On 10/16/2009 07:53 AM, Pauli Virtanen wrote:
> Fri, 16 Oct 2009 12:07:10 +0200, Francesc Alted wrote:
> [clip]
>
>> IMO, NumPy can be improved for unaligned data handling. For example,
>> Numexpr is using this small snippet:
>>
>> from cpuinfo import cpu
>> if cpu.is_AMD() or cpu.is_Intel():
>> is_cpu_amd_intel = True
>> else:
>> is_cpu_amd_intel = False
>>
>> for detecting AMD/Intel architectures and allowing the code to avoid
>> memcpy() calls for the unaligned arrays.
>>
>> The above code uses the excellent ``cpuinfo.py`` module from Pearu
>> Peterson, which is distributed under NumPy, so it should not be too
>> difficult to take advantage of this for avoiding unnecessary copies in
>> this scenario.
>>
> I suppose this kind of check is easiest to do at compile-time, and
> defining a -DFORCE_ALIGNED? This wouldn't cause performance penalties for
> those architectures for which they are not necessary.
>
>
That's close to the solution I'm arriving at.
I'm thinking of adding a macro "DEREF_UNALIGNED_PYOBJECT_PTR" which
would do the right thing depending on the type of architecture. There
should be no impact on architectures that handle unaligned pointers, and
slightly slower (but correct) performance on other architectures.
Mike
More information about the NumPy-Discussion
mailing list