c++ - Increasing speed of float calculations at the cost of accuracy? -
i have program contains large arrays of float values, , performs lot of calculations based on them, these values later scaled fall between 0 , 255 act pixel values. possible reduce accuracy of floating point calculations, works say, 4 significant figures, increases speed, , reduce size of array in memory?
i using c++, g++ compile on linux, , boost multi arrays.
thanks, angus
generally, modern processors not have narrower floating-point 32-bit arithmetic. have provisions loading , storing 16-bit floating-point objects, convert them 32-bit objects loaded , arithmetic 32-bit objects. there might advantage doing integer arithmetic floating-point arithmetic, explained below.
in of today’s hardware, normal floating-point operations on par simplest operations in processor. there may ways speed arithmetic, may require specialized knowledge of specific hardware using , considerable investment in software development.
it not uncommon throughput of processor same floating-point operations integer operations. throughput number of operations per second processor can do. however, floating-point operations may have longer latencies. common situation processor can complete integer addition in 1 processor cycle, , processor can complete floating-point addition in 4 cycles, work in 4 parts, , each part can work on different addition @ same time other parts. although 4 cycles start of floating-point addition until done, processor still completes 1 addition per cycle.
a consequence of chain of arithmetic such a+b+c requires 8 cycles complete in floating-point 2 cycles in integer. in contrast, separate, unchained arithmetic, such a+b, c+d, e+f, , g+h takes same amount of time in floating-point or integer. so, whether or not feature arithmetic depends on specifics of arithmetic.
another feature many modern processors have called simd, single instruction multiple data. feature allows processor execute several arithmetic operations simultaneously (often 4 32-bit integer operations or 4 32-bit floating-point operations, more operations narrower integers, fewer operations 64-bit floating-point). accessing simd features general c++ code troublesome. compilers provide automatic use of this. so, requires knowledge of , attention specific details, such data alignment, issues can interfere parallelization of operations, , informing compiler specific processor models compiled code execute on. simd features can accessed special compiler built-ins, macros, and/or language extensions or assembly language.
image processing popular area, , software libraries have been written use simd features provide common image processing operations, such image scaling, image rotation, color transformation, filters such sharpening or blurring, , others.
since mention linux, , not work linux, leave others discuss libraries available.
Comments
Post a Comment