Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Does ?copy guarantee overlapping regions ?

newton_particle
Beginner
489 Views
Does anyone know how if ?copy has guarantees for overlapping source/target regions?

i.e. is it more memmove() than memcpy(), so that the direction of copying is factored in to prevent overruns ?

Newton
--------
0 Kudos
1 Reply
TimP
Honored Contributor III
489 Views
Quoting - newton_particle
Does anyone know how if ?copy has guarantees for overlapping source/target regions?

i.e. is it more memmove() than memcpy(), so that the direction of copying is factored in to prevent overruns ?

BLAS ?COPY has no protection against overlaps. You could build the netlib reference source code yourself, with compiler options which protect against overlap, such as ifort -assume dummy_aliases, but this is likely to be less efficient than memmove(), or copying first to a temporary region, then to the final target. It's possible to invoke memmove() directly from a Fortran compiler which supports ISO C interoperability (somewhat ugly).
Backwards copy is usually slow anyway (barring specially aligned cases) on Intel processors prior to Core i7, and AMD processors prior to Barcelona, so it's not safe to assume that an implementation of memmove() or equivalent is the most efficient one for your processor, unless you write/test it yourself. This may require fairly low level code, such as SSE intrinsics.
If you used ?COPY incorrectly, with overlapping data, it wouldn't necessarily be an over-run, but the source data would be over-written before use. memmove() likewise has no protection against over-run, should you exceed the target limits.
0 Kudos
Reply