jacobian

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 6f012f346097d5211da2a217b2648e6903cbf305
parent a6f363eaa4ef852062ab2ac8ea969ba6fdad3087
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Fri, 25 Sep 2020 14:38:52 -0700

Attribution + readv() improvements

Diffstat:
Msrc/cnn.cpp | 1+
Msrc/experimental/fileread.cpp | 29+++++++++++++++++++----------
2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/cnn.cpp b/src/cnn.cpp @@ -19,6 +19,7 @@ #define checknan(x, loc) #endif +// NOTE: Below two functions not mine, from https://compvisionlab.wordpress.com/2014/01/01/c-code-for-reading-mnist-data-set/ int ReverseInt (int i) { unsigned char ch1, ch2, ch3, ch4; diff --git a/src/experimental/fileread.cpp b/src/experimental/fileread.cpp @@ -128,22 +128,31 @@ float mmap_read() float vec_read() { +#define CHUNK_SZ 512 +#define BUFFER_SZ 512*1024 +#define NUM_CHUNKS BUFFER_SZ/CHUNK_SZ int fd = open("../../data_banknote_authentication.bin", O_RDONLY | O_NONBLOCK); - float buf[128]; - float buf2[128]; - float buf3[128]; - float buf4[128]; - float buf5[128]; - float buf6[128]; - float buf7[128]; - float buf8[128]; - iovec iovecs[8] {{&buf, 512}, {&buf2, 512}, {&buf3, 512}, {&buf4, 512}, {&buf5, 512}, {&buf6, 512}, {&buf7, 512}, {&buf8, 512}}; - while(size_t bytes_read = readv(fd, iovecs, 8)) + char rawbuf[BUFFER_SZ]; + char* buf = (char*) rawbuf; + iovec iovecs[NUM_CHUNKS]; + // printf("buf = %p\n", buf); + for (int i = 0; i < BUFFER_SZ; i+=CHUNK_SZ) { + // printf("iovecs[%d] = {%p, %d}\n", i/512, buf + i, 512); + iovecs[i/CHUNK_SZ].iov_base = buf + i; + iovecs[i/CHUNK_SZ].iov_len = CHUNK_SZ; + } + while(size_t bytes_read = readv(fd, iovecs, NUM_CHUNKS)) { if(bytes_read == (size_t)-1) { + printf("\n%zu\n", bytes_read); printf("bytes_read == (size_t)-1\n"); exit(1); } + // for(char *p = buf; p < buf+512;) { + // for (int i=0; i<5; ++i) { + // p += sizeof(float); + // } + // } if (!bytes_read) break; } }