Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _GNU_SOURCE
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/mman.h>
- #include <stdint.h>
- #include <string.h>
- #include <unistd.h>
- #include <omp.h>
- #include <x86intrin.h>
- #define bind(f, arg) ({typeof(f(arg)) new(void) { return f(arg);} new;})
- #define bind2(f, arg, arg2) ({typeof(f(arg, arg2)) new(void) { return f(arg, arg2);} new;})
- #define bind3(f, arg, arg2, arg3) ({typeof(f(arg, arg2, arg3)) new(void) { return f(arg, arg2, arg3);} new;})
- static inline void * alloc(uint64_t size, uint64_t flags) {
- return mmap(NULL, size, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS | flags, 0, 0);
- }
- typedef void*(*vpvf_t)(void);
- #define GB (1024ul*1024*1024)
- #define KB (1024)
- void bench_memcpy(uint64_t total, uint64_t pass, vpvf_t f) {
- uint64_t i = (total/pass);
- double start = omp_get_wtime();
- do {f();} while(--i);
- double time = omp_get_wtime() - start;
- fprintf(stderr, "%fGB/s\n", ((total * 2)/GB)/time);
- }
- void * cachecp32(__m256i * to, __m256i * from, uint64_t n) {
- typeof(from) from_end = ((void *)from + n), ret = to;
- do {
- _mm256_store_si256(to++, _mm256_load_si256(from++));
- } while(from != from_end);
- return ret;
- }
- void * cachecp512(__m256i * to, __m256i * from, uint64_t n) {
- typeof(from) from_end = ((void *)from + n), ret = to;
- do {
- *to++ = *from++;
- *to++ = *from++;
- *to++ = *from++;
- *to++ = *from++;
- *to++ = *from++;
- *to++ = *from++;
- *to++ = *from++;
- *to++ = *from++;
- *to++ = *from++;
- *to++ = *from++;
- *to++ = *from++;
- *to++ = *from++;
- *to++ = *from++;
- *to++ = *from++;
- *to++ = *from++;
- *to++ = *from++;
- } while(from != from_end);
- return ret;
- }
- int main(void) {
- vpvf_t alloc1gb = bind2(alloc, GB, MAP_POPULATE);
- void * from = alloc1gb(), * to = alloc1gb();
- uint64_t block_size = KB, total = GB*128;
- do {
- fprintf(stderr, "\nBLOCK SIZE: %luKB\n", block_size/KB);
- fprintf(stderr, "cachecp32:\n");
- bench_memcpy(total, block_size, bind3(cachecp32, to, from, block_size));
- fprintf(stderr, "cachecp512:\n");
- bench_memcpy(total, block_size, bind3(cachecp512, to, from, block_size));
- } while((block_size *= 2) != (sysconf(_SC_LEVEL1_DCACHE_SIZE)/2));
- }
Advertisement
Add Comment
Please, Sign In to add comment