| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #ifndef __APPLE__ | ||
| 8 | # include <malloc.h> | ||
| 9 | #else | ||
| 10 | # include <stdlib.h> | ||
| 11 | #endif | ||
| 12 | |||
| 13 | #include <iostream> | ||
| 14 | #include "hadamard_product.h" | ||
| 15 | |||
| 16 | #define VECTOR_ALIGNEMENT 64lu | ||
| 17 | |||
| 18 | #ifdef __APPLE__ | ||
| 19 | ///Alloc an aligned vector | ||
| 20 | /** @param sizeOfVectorInBytes : size of the vector xe want to allocate | ||
| 21 | * @param alignementInBytes : alignement of the vector we want to allocate | ||
| 22 | * @return aligned pointor of the vector | ||
| 23 | */ | ||
| 24 | void * memalign(long unsigned int alignementInBytes, long unsigned int sizeOfVectorInBytes){ | ||
| 25 | void * ptr = NULL; | ||
| 26 | posix_memalign(&ptr, alignementInBytes, sizeOfVectorInBytes); | ||
| 27 | return ptr; | ||
| 28 | } | ||
| 29 | #endif | ||
| 30 | |||
| 31 | ///Do the aligned allocation of a pointer | ||
| 32 | /** @param sizeOfVectorInBytes : number of bytes to be allocated | ||
| 33 | * @return allocated pointer | ||
| 34 | */ | ||
| 35 | 3 | void * custom_aligned_malloc(long unsigned int sizeOfVectorInBytes){ | |
| 36 | 3 | return memalign(VECTOR_ALIGNEMENT, sizeOfVectorInBytes); | |
| 37 | } | ||
| 38 | |||
| 39 | ///Free an aligned pointer | ||
| 40 | /** @param ptr : ptr to be freed | ||
| 41 | */ | ||
| 42 | 3 | void custom_aligned_free(void* ptr){ | |
| 43 | 3 | free(ptr); | |
| 44 | 3 | } | |
| 45 | |||
| 46 | ///Test the proxy library | ||
| 47 | 1 | void testProxyLib(){ | |
| 48 | 1 | size_t nbElement(1000lu); | |
| 49 | 1 | float * tabX = (float*)custom_aligned_malloc(sizeof(float)*nbElement); | |
| 50 | 1 | float * tabY = (float*)custom_aligned_malloc(sizeof(float)*nbElement); | |
| 51 | 1 | float * tabRes = (float*)custom_aligned_malloc(sizeof(float)*nbElement); | |
| 52 | |||
| 53 |
2/2✓ Branch 0 (7→6) taken 1000 times.
✓ Branch 1 (7→8) taken 1 times.
|
1001 | for(size_t i(0lu); i < nbElement; ++i){ |
| 54 | 1000 | tabX[i] = i*19lu%11; | |
| 55 | 1000 | tabY[i] = i*27lu%19; | |
| 56 | } | ||
| 57 | |||
| 58 | 1 | hadamard_product(tabRes, tabX, tabY, nbElement); | |
| 59 | 1 | std::cout << "testProxyLib = tabRes[0] = " << tabRes[0] << std::endl; | |
| 60 | 1 | custom_aligned_free(tabRes); | |
| 61 | 1 | custom_aligned_free(tabY); | |
| 62 | 1 | custom_aligned_free(tabX); | |
| 63 | 1 | } | |
| 64 | |||
| 65 | 1 | int main(int argc, char** argv){ | |
| 66 | 1 | testProxyLib(); | |
| 67 | 1 | return 0; | |
| 68 | } | ||
| 69 | |||
| 70 | |||
| 71 |