14 #define _XOPEN_SOURCE 700
22 #include <sys/types.h>
28 #include <cuda_runtime.h>
33 #include "sion_error_handler.h"
46 #define TABLE_SIZE 127
48 #define SEARCH_TO_KEY 0
49 #define SEARCH_TO_NEXT 1
50 #define SEARCH_TO_END 2
55 int _sion_scan_forward_to_key(
_sion_filedesc *sion_filedesc, uint64_t key,
int search_mode);
57 size_t _sion_write_data_to_chunks_inline(
_sion_filedesc *sion_filedesc,
const void *data, sion_int64 bytes_to_write);
58 sion_int64 _sion_compute_next_position_inline(
_sion_filedesc *sion_filedesc, sion_int64 bytes_to_read);
59 size_t _sion_skip_data_from_chunks_inline(
_sion_filedesc *sion_filedesc, sion_int64 bytes_to_read);
60 size_t _sion_read_data_from_chunks_inline(
_sion_filedesc *sion_filedesc,
void *data, sion_int64 bytes_to_read);
69 #define DFUNCTION "_sion_store_and_write_key_and_len_inline"
70 size_t _sion_store_and_write_key_and_len_inline(
_sion_filedesc *sion_filedesc, uint64_t key,
size_t len) {
71 sion_int64 bytes_to_write;
73 size_t rc=SION_SUCCESS, frc;
76 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
81 buffer[0]=(sion_int64) key;
82 buffer[1]=(sion_int64) len;
83 bytes_to_write=2*
sizeof(sion_int64);
85 frc=_sion_write_data_to_chunks_inline(sion_filedesc, (
const void *) buffer, (sion_int64) bytes_to_write);
88 if(frc != bytes_to_write) {
89 return(_sion_errorprint_on_rank(-1,_SION_ERROR_RETURN,sion_filedesc->
rank,
90 "could not write data (%d bytes) to file (frc=%d sid=%d) ...", (
int) bytes_to_write, (
int) frc, sion_filedesc->
sid));
93 DPRINTFP((2, DFUNCTION, -1,
"leave rc=%d\n",rc));
98 #define DFUNCTION "_sion_write_value_inline"
99 size_t _sion_write_value_inline(
_sion_filedesc *sion_filedesc,
const void *data, uint64_t key,
size_t len) {
101 sion_int64 bytes_to_write;
102 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
106 frc=_sion_write_data_to_chunks_inline(sion_filedesc, data, (sion_int64) bytes_to_write);
107 if(frc != bytes_to_write) {
108 return(_sion_errorprint_on_rank(-1,_SION_ERROR_RETURN,sion_filedesc->
rank,
109 "could not write data (%d bytes) to file (frc=%d sid=%d) ...", (
int) bytes_to_write, (
int) frc, sion_filedesc->
sid));
112 rc=(size_t) bytes_to_write;
114 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
124 #define DFUNCTION "_sion_find_and_read_key_and_len_inline"
125 int _sion_find_and_read_key_and_len_inline(
_sion_filedesc *sion_filedesc, uint64_t key,
size_t len,
size_t *datalen) {
128 int position_found=0;
129 sion_table_key_t mkey;
130 size_t key_current_pos = (size_t) -1, key_bytes_left = (
size_t) -1;
132 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
135 keymngr=_sion_get_or_init_key_info(sion_filedesc);
146 rc=_sion_keyvalue_keymngr_lookup(keymngr, mkey, &key_current_pos, &key_bytes_left);
147 if(rc!=SION_SUCCESS) {
148 DPRINTFP((2, DFUNCTION, -1,
"key %ld is not found in keymngr, scan forward\n", (
long)mkey));
151 rc=_sion_scan_forward_to_key(sion_filedesc, key, SEARCH_TO_KEY);
154 if(rc==SION_SUCCESS) {
155 DPRINTFP((2, DFUNCTION, -1,
"scan forward found key %ld, get info \n", (
long)mkey));
156 rc=_sion_keyvalue_keymngr_lookup(keymngr, mkey, &key_current_pos, &key_bytes_left);
157 DPRINTFP((2, DFUNCTION, -1,
"key %ld, get info(2): pos=%ld bytes_left=%ld\n", (
long)mkey, (
long) key_current_pos, (
long) key_bytes_left ));
160 DPRINTFP((2, DFUNCTION, -1,
"key %ld, get info(1): pos=%ld bytes_left=%ld\n", (
long)mkey, (
long) key_current_pos, (
long) key_bytes_left ));
162 if(rc==SION_SUCCESS) {
165 if(len<=key_bytes_left) {
169 *datalen=key_bytes_left;
174 DPRINTFP((2, DFUNCTION, -1,
"no more data for key %ld\n", (
long)mkey ));
178 DPRINTFP((2, DFUNCTION, -1,
"check position: current_pos %ld, key_current_pos=%ld len=%ld key_bytes_left=%ld\n",
179 (
long) sion_filedesc->
currentpos, (
long) key_current_pos, (
long) len, (
long) key_bytes_left ));
181 if(key_current_pos!=sion_filedesc->
currentpos) {
182 rc=_sion_move_to_pos(sion_filedesc, key_current_pos);
187 DPRINTFP((2, DFUNCTION, -1,
"leave rc=%d\n", rc));
192 #define DFUNCTION "_sion_read_value_inline"
193 size_t _sion_read_value_inline(
_sion_filedesc *sion_filedesc,
void *data, uint64_t key,
size_t len) {
196 sion_table_key_t mkey;
198 sion_int64 bytes_to_read;
201 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
204 keymngr=_sion_get_or_init_key_info(sion_filedesc);
205 mkey = (sion_table_key_t) key;
214 bread=_sion_read_data_from_chunks_inline(sion_filedesc, (
void *) out, (sion_int64) bytes_to_read);
215 if (bread != bytes_to_read) {
216 return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc->
rank,
217 "could not read data (%d bytes) from file ...", (
int) bytes_to_read));
220 DPRINTFP((2, DFUNCTION, -1,
"first value = %3hhu | %c\n", out[0], out[0]));
223 _sion_keyvalue_keymngr_update_read_pos(keymngr, mkey, (
size_t) bread, (sion_int64) sion_filedesc->
currentpos);
227 DPRINTFP((2, DFUNCTION, -1,
"leave rc=%d\n",(
int) rc));
233 #define DFUNCTION "_sion_key_full_scan_inline"
235 int rc=SION_NOT_SUCCESS;
237 sion_table_key_t key=0;
239 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
242 keymngr=_sion_get_or_init_key_info(sion_filedesc);
244 if(!_sion_keyvalue_keymngr_is_scan_done(keymngr)) {
245 rc=_sion_scan_forward_to_key(sion_filedesc, key, SEARCH_TO_END);
251 DPRINTFP((2, DFUNCTION, -1,
"leave rc=%d\n",rc));
257 #define DFUNCTION "_sion_iterator_reset_inline"
262 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
265 keymngr=_sion_get_or_init_key_info(sion_filedesc);
267 rc=_sion_keyvalue_keymngr_iterator_reset(keymngr);
269 DPRINTFP((2, DFUNCTION, -1,
"leave rc=%d\n",rc));
274 #define DFUNCTION "_sion_iterator_next_inline"
275 int _sion_iterator_next_inline(
_sion_filedesc *sion_filedesc, uint64_t *keyptr,
size_t *sizeptr) {
276 int rc=SION_NOT_SUCCESS;
278 sion_table_key_t key=0;
279 size_t current_pos, offset, len;
281 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
284 keymngr=_sion_get_or_init_key_info(sion_filedesc);
286 if(_sion_keyvalue_keymngr_iterator_next(keymngr, &key, ¤t_pos, &offset, &len)==SION_SUCCESS) {
291 if (_sion_scan_forward_to_key(sion_filedesc, key, SEARCH_TO_NEXT)==SION_SUCCESS) {
293 if(_sion_keyvalue_keymngr_iterator_next(keymngr, &key, ¤t_pos, &offset, &len)==SION_SUCCESS) {
296 return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN, sion_filedesc->
rank,
297 "internal error: block could not be find at end of block list ..."));
306 if(rc==SION_SUCCESS) {
307 *keyptr = (uint64_t) key;
308 *sizeptr = (size_t) len;
311 DPRINTFP((2, DFUNCTION, -1,
"leave rc=%d\n",rc));
316 #define DFUNCTION "_sion_seek_key_inline"
317 int _sion_seek_key_inline(
_sion_filedesc *sion_filedesc, uint64_t key,
int blocknum, sion_int64 posinblock) {
318 int rc=SION_NOT_SUCCESS;
322 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
325 keymngr=_sion_get_or_init_key_info(sion_filedesc);
328 rc=_sion_keyvalue_keymngr_lookup_and_set_pos(keymngr, key, blocknum, posinblock, &offset, &len);
329 DPRINTFP((2, DFUNCTION, -1,
"after first lookup rc=%d offset=%d len=%d\n",rc, (
int)offset, (
int) len ));
331 while( (rc!=SION_SUCCESS) && !_sion_keyvalue_keymngr_is_scan_done(keymngr) ) {
334 DPRINTFP((2, DFUNCTION, -1,
"scan forward to find key %d\n",(
int) key));
335 if (_sion_scan_forward_to_key(sion_filedesc, key, SEARCH_TO_NEXT)==SION_SUCCESS) {
338 rc=_sion_keyvalue_keymngr_lookup_and_set_pos(keymngr, key, blocknum, posinblock, &offset, &len);
339 DPRINTFP((2, DFUNCTION, -1,
"in loop lookup rc=%d offset=%d len=%d\n",rc, (
int)offset, (
int) len ));
346 if( rc==SION_SUCCESS ) {
347 DPRINTFP((2, DFUNCTION, -1,
"move from %ld to new scanpos (%ld) \n",(
long) sion_filedesc->
currentpos,(
long) offset));
348 rc=_sion_move_to_pos(sion_filedesc, offset);
351 DPRINTFP((2, DFUNCTION, -1,
"leave rc=%d\n",rc));
356 #define DFUNCTION "_sion_key_list_iterator_reset_inline"
357 int _sion_key_list_iterator_reset_inline(
_sion_filedesc *sion_filedesc) {
361 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
364 keymngr=_sion_get_or_init_key_info(sion_filedesc);
366 rc=_sion_keyvalue_keymngr_key_list_iterator_reset(keymngr);
368 DPRINTFP((2, DFUNCTION, -1,
"leave rc=%d\n",rc));
373 #define DFUNCTION "_sion_iterator_next_inline"
374 int _sion_key_list_iterator_next_inline(
_sion_filedesc *sion_filedesc, uint64_t *keyptr) {
375 int rc=SION_NOT_SUCCESS;
377 sion_table_key_t key=0;
379 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
382 keymngr=_sion_get_or_init_key_info(sion_filedesc);
384 if(_sion_keyvalue_keymngr_key_list_iterator_next(keymngr, &key)==SION_SUCCESS) {
385 *keyptr = (uint64_t) key;
392 DPRINTFP((2, DFUNCTION, -1,
"leave rc=%d key=%ld\n",rc,(
long) key));
398 #define DFUNCTION "_sion_key_get_stat_inline"
400 int rc=SION_NOT_SUCCESS;
402 sion_table_key_t key=0;
404 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
407 keymngr=_sion_get_or_init_key_info(sion_filedesc);
409 key= (sion_table_key_t) searchkey;
411 if(_sion_keyvalue_keymngr_key_get_stat(keymngr, key, keystat)==SION_SUCCESS) {
417 DPRINTFP((2, DFUNCTION, -1,
"leave rc=%d key=%ld\n",rc,(
long) key));
426 #define DFUNCTION "_sion_scan_forward_to_key"
427 int _sion_scan_forward_to_key(
_sion_filedesc *sion_filedesc, uint64_t key,
int search_mode) {
428 int rc = SION_SUCCESS;
430 sion_table_key_t mkey;
434 size_t bytes_left, lastposinblock, lastposinfile;
435 uint64_t key_and_len[2];
437 size_t bread, bskip, len;
439 DPRINTFP((2, DFUNCTION, -1,
"enter key=%ld\n",(
long) key));
447 if(_sion_keyvalue_keymngr_get_next_scan_pos(keymngr, &scanpos) != SION_SUCCESS) {
450 DPRINTFP((2, DFUNCTION, -1,
"set scanpos to first pos in file pos=%ld\n",(
long) scanpos));
456 DPRINTFP((2, DFUNCTION, -1,
"check if not already scanned to endoffile scanpos=%ld lastposinfile=%ld lastchunknr=%d\n",(
long) scanpos,(
long) lastposinfile, (
int) sion_filedesc->
lastchunknr ));
457 if(scanpos>=lastposinfile) {
458 DPRINTFP((2, DFUNCTION, -1,
"scan is already at end of file (%ld>=%ld) \n",(
long) scanpos, (
long) lastposinfile));
459 _sion_keyvalue_keymngr_set_scan_done(keymngr);
464 if( (sion_filedesc->
currentpos != scanpos) && (!_sion_keyvalue_keymngr_is_scan_done(keymngr)) ) {
465 DPRINTFP((2, DFUNCTION, -1,
"move from %ld to new scanpos (%ld) \n",(
long) sion_filedesc->
currentpos,(
long) scanpos));
466 rc=_sion_move_to_pos(sion_filedesc, scanpos);
470 while ( (!_sion_keyvalue_keymngr_is_scan_done(keymngr)) && (!key_found) ) {
474 bytes_left = lastposinblock - sion_filedesc->
currentpos;
475 DPRINTFP((2, DFUNCTION, -1,
"search loop: lastposinblock=%ld bytes_left=%ld currentpos=%ld\n",(
long) lastposinblock,(
long) bytes_left,(
long) sion_filedesc->
currentpos));
479 if ( bytes_left > 0 ) {
481 bread=_sion_read_data_from_chunks_inline(sion_filedesc, (
void *) key_and_len, (sion_int64)
sizeof(key_and_len));
482 if (bread !=
sizeof(key_and_len)) {
483 return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc->
rank,
484 "could not read data (%d bytes) from file ...", (
int)
sizeof(key_and_len)));
489 DPRINTFP((2, DFUNCTION, -1,
"search loop: found next key,len (%ld,%ld)\n",(
long) key_and_len[0],(
long) key_and_len[1]));
492 DPRINTFP((2, DFUNCTION, -1,
"search loop: position is now %ld bytes_left=%ld\n",(
long) sion_filedesc->
currentpos, (
long) bytes_left));
496 DPRINTFP((2, DFUNCTION, -1,
"search loop: data starts in next chunk, moving forward\n"));
497 if(! _sion_move_to_next_chunk(sion_filedesc)) {
498 return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc->
rank,
499 "could not move to data section in next block ..."));
503 bytes_left = lastposinblock - sion_filedesc->
currentpos;
504 DPRINTFP((2, DFUNCTION, -1,
"search loop: position is moved to %ld bytes_left=%ld\n",(
long) sion_filedesc->
currentpos, (
long) bytes_left));
510 rc=_sion_keyvalue_keymngr_add_block(keymngr, mkey, (
size_t) sion_filedesc->
currentpos, len);
511 DPRINTFP((2, DFUNCTION, -1,
"search loop: stored new block key=%ld pos=%ld len=%ld\n",(
long) mkey, (
long) sion_filedesc->
currentpos, (
long) len));
515 ( ( (search_mode==SEARCH_TO_KEY) && (key_and_len[0] == key) ) || (search_mode==SEARCH_TO_NEXT) )
516 && ( !(search_mode==SEARCH_TO_END) )
518 DPRINTFP((2, DFUNCTION, -1,
"search loop: found searched key=%ld, leaving\n",(
long) key));
521 scanpos=_sion_compute_next_position_inline(sion_filedesc, len);
523 DPRINTFP((2, DFUNCTION, -1,
"search loop: found another key=%ld <=> %ld, continue\n",(
long) key_and_len[0], (
long) key));
526 DPRINTFP((2, DFUNCTION, -1,
"search loop: found move position forward by %ld bytes\n",(
long) len));
527 bskip=_sion_skip_data_from_chunks_inline(sion_filedesc, (sion_int64) len);
529 if ( bskip == len ) {
534 bytes_left = lastposinblock - sion_filedesc->
currentpos;
538 return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc->
rank,
539 "could not skip data section of one block (%d bytes) from file ...", (
int) len));
544 DPRINTFP((2, DFUNCTION, -1,
"search loop: chunk empty, move to next chunk\n"));
545 if(! _sion_move_to_next_chunk(sion_filedesc)) {
546 _sion_keyvalue_keymngr_set_scan_done(keymngr);
547 if(search_mode!=SEARCH_TO_END) {
559 if(! _sion_move_to_next_chunk(sion_filedesc)) {
560 _sion_keyvalue_keymngr_set_scan_done(keymngr);
564 return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc->
rank,
565 "unknown data at end of chunk (%d bytes) ...", (
int) bytes_left));
572 if(_sion_keyvalue_keymngr_set_next_scan_pos(keymngr, scanpos) != SION_SUCCESS) {
573 return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc->
rank,
574 "internal error set seekpos ..."));
577 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
583 #define DFUNCTION "_sion_get_or_init_key_info"
588 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
591 DPRINTFP((2, DFUNCTION, -1,
"sion_filedesc->keyvalptr == NULL\n"));
592 keymngr =_sion_keyvalue_keymngr_init(TABLE_SIZE);
593 if (keymngr == NULL) {
594 _sion_errorprint_on_rank(-1,_SION_ERROR_RETURN,sion_filedesc->
rank,
"could not allocate keymngr ...");
597 DPRINTFP((2, DFUNCTION, -1,
"alloc now KEYVALPTR = %x\n",sion_filedesc->
keyvalptr));
600 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
605 #define DFUNCTION "_sion_move_to_next_chunk"
607 int rc = SION_SUCCESS;
609 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
622 DPRINTFP((2, DFUNCTION, -1,
"leave, rc = %d\n", rc));
627 #define DFUNCTION "_sion_move_to_pos"
628 int _sion_move_to_pos(
_sion_filedesc *sion_filedesc,
size_t pos) {
629 int rc = SION_SUCCESS;
630 size_t block_min_pos, block_max_pos;
633 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
638 DPRINTFP((2, DFUNCTION, -1,
"current_chunk: %ld to %ld (pos=%ld)\n", (
long) block_min_pos, (
long) block_max_pos, (
long) pos));
640 if ( (pos>=block_min_pos) && (pos<block_max_pos) ) {
646 DPRINTFP((2, DFUNCTION, -1,
"stay in current chunk: currentpos=%ld\n", (
long) sion_filedesc->
currentpos));
653 block_max_pos = block_min_pos+sion_filedesc->
blocksizes[c];
655 DPRINTFP((2, DFUNCTION, -1,
"check chunk%2d: %ld to %ld (pos=%ld)\n", c, (
long) block_min_pos, (
long) block_max_pos, (
long) pos));
657 if ( (pos>=block_min_pos) && (pos<block_max_pos) ) {
665 DPRINTFP((2, DFUNCTION, -1,
"stay in this chunk: currentpos=%ld\n", (
long) sion_filedesc->
currentpos));
676 DPRINTFP((2, DFUNCTION, -1,
"leave, rc = %d\n", rc));
682 #define DFUNCTION "_sion_write_data_to_chunks_inline"
683 size_t _sion_write_data_to_chunks_inline(
_sion_filedesc *sion_filedesc,
const void *data, sion_int64 bytes_to_write) {
684 sion_int64 btowr, byteswritten, offset;
688 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
692 while(bytes_to_write>0) {
698 btowr=bytes_to_write;
699 if ((byteswritten + btowr) > sion_filedesc->
chunksize) btowr = sion_filedesc->
chunksize - byteswritten;
700 DPRINTFP((2, DFUNCTION, -1,
" bytes_to_write=%ld btowr=%ld chunksize=%ld byteswritten=%ld currentblocknr=%d blsize[%d]=%ld\n",
701 (
long) bytes_to_write, (
long) btowr, (
long) sion_filedesc->
chunksize, (
long) byteswritten, (
int) sion_filedesc->
currentblocknr,
706 struct cudaPointerAttributes attrs;
707 cudaError_t err = cudaPointerGetAttributes(&attrs, data);
708 if ((err == cudaSuccess) && _sion_cuda_ptr_is_device(attrs) ) {
709 char* buffer = malloc(sion_filedesc->
fsblksize);
710 const char* data_ = (
char *)data + offset;
711 while (frc < btowr) {
712 sion_int64 to_write = (btowr - frc) > sion_filedesc->
fsblksize ? sion_filedesc->
fsblksize : (btowr - frc);
713 cudaMemcpy(buffer, data_, to_write, cudaMemcpyDeviceToHost);
715 if (frc_ != to_write)
break;
729 return(_sion_errorprint_on_rank(-1,_SION_ERROR_RETURN,sion_filedesc->
rank,
730 "could not write data (%d bytes) to file (frc=%d sid=%d) ...", (
int) btowr, (
int) frc, sion_filedesc->
sid));
735 bytes_to_write -=btowr;
739 if(bytes_to_write>0) {
747 DPRINTFP((2, DFUNCTION, -1,
"leave rc=%d\n",rc));
753 #define DFUNCTION "_sion_compute_next_position_inline"
754 sion_int64 _sion_compute_next_position_inline(
_sion_filedesc *sion_filedesc, sion_int64 bytes_to_read) {
755 sion_int64 btord = 0, bytesread = 0, offset = 0;
759 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
765 DPRINTFP((2, DFUNCTION, -1,
" currentpos=%ld bytesread=%ld blocknr=%d bytes_to_read=%ld\n",
766 (
long) sion_filedesc->
currentpos, (
long) bytesread, (
int) blocknr, (
long) bytes_to_read ));
768 DPRINTFP((2, DFUNCTION, -1,
" blocksizes[%d]=%ld\n",
773 offset=sion_filedesc->
currentpos+bytes_to_read;
776 bytes_to_read-=btord;
778 DPRINTFP((2, DFUNCTION, -1,
" skip to next block, bytes_to_read=%ld btord=%ld\n",(
long) bytes_to_read, (
long) btord ));
781 while(bytes_to_read>0) {
784 if (blocknr < sion_filedesc->lastchunknr) { blocknr++; }
else {
785 return(_sion_errorprint_on_rank(-1,_SION_ERROR_RETURN,sion_filedesc->
rank,
"internal error next block not available, but should ..."));
788 DPRINTFP((2, DFUNCTION, -1,
" blocksizes[%d]=%ld\n", (
int) blocknr, (
long) sion_filedesc->
blocksizes[blocknr] ));
789 if ( bytes_to_read > sion_filedesc->
blocksizes[blocknr]) {
791 bytes_to_read-=btord;
792 DPRINTFP((2, DFUNCTION, -1,
"whole block, bytes_to_read=%ld btord=%ld\n",(
long) bytes_to_read, (
long) btord ));
803 if (blocknr < sion_filedesc->lastchunknr) {
806 DPRINTFP((2, DFUNCTION, -1,
" behind end of block, move to next block, blocksizes[%d]=%ld\n", (
int) blocknr, (
long) sion_filedesc->
blocksizes[blocknr] ));
811 DPRINTFP((2, DFUNCTION, -1,
"leave offset=%ld\n",(
long) offset));
817 #define DFUNCTION "_sion_skip_data_from_chunks_inline"
818 size_t _sion_skip_data_from_chunks_inline(
_sion_filedesc *sion_filedesc, sion_int64 bytes_to_read) {
819 sion_int64 btord, bytesread, offset;
823 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
827 while(bytes_to_read>0) {
835 DPRINTFP((2, DFUNCTION, -1,
" bytes_to_read=%ld btord=%ld\n",(
long) bytes_to_read, (
long) btord ));
841 bytes_to_read -=btord;
845 if(bytes_to_read>0) {
847 if(! _sion_move_to_next_chunk(sion_filedesc)) {
848 return(_sion_errorprint_on_rank(-1,_SION_ERROR_RETURN,sion_filedesc->
rank,
849 "could not read data (%d bytes) to file (end of file reached sid=%d) ...", (
int) btord, sion_filedesc->
sid));
860 DPRINTFP((2, DFUNCTION, -1,
"leave rc=%d\n",rc));
866 #define DFUNCTION "_sion_read_data_from_chunks_inline"
867 size_t _sion_read_data_from_chunks_inline(
_sion_filedesc *sion_filedesc,
void *data, sion_int64 bytes_to_read) {
868 sion_int64 btord, bytesread, offset;
872 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
876 while(bytes_to_read>0) {
880 DPRINTFP((2, DFUNCTION, -1,
"bytesread=%ld, curpos=%ld,startpos=%ld,curblock=%ld,gskip=%ld\n",
887 DPRINTFP((2, DFUNCTION, -1,
"block is split to multiple chunks, bytes_to_read=%ld btord=%ld\n",(
long) bytes_to_read, (
long) btord ));
889 DPRINTFP((2, DFUNCTION, -1,
"block in one chunk, bytes_to_read=%ld btord=%ld\n",(
long) bytes_to_read, (
long) btord ));
894 struct cudaPointerAttributes attrs;
895 cudaError_t err = cudaPointerGetAttributes(&attrs, data);
896 if ((err == cudaSuccess) && _sion_cuda_ptr_is_device(attrs) ) {
897 char* buffer = malloc(sion_filedesc->
fsblksize);
898 char* data_ = (
char *)data + offset;
899 while (frc < btord) {
900 sion_int64 to_read = (btord - frc) > sion_filedesc->
fsblksize ? sion_filedesc->
fsblksize : (btord - frc);
902 if (frc_ != to_read)
break;
903 cudaMemcpy(data_, buffer, frc_, cudaMemcpyHostToDevice);
917 return(_sion_errorprint_on_rank(-1,_SION_ERROR_RETURN,sion_filedesc->
rank,
918 "could not read data (%d bytes) to file (frc=%d sid=%d) ...", (
int) btord, (
int) frc, sion_filedesc->
sid));
923 bytes_to_read -=btord;
927 if(bytes_to_read>0) {
929 if(! _sion_move_to_next_chunk(sion_filedesc)) {
930 return(_sion_errorprint_on_rank(-1,_SION_ERROR_RETURN,sion_filedesc->
rank,
931 "could not read data (%d bytes) to file (end of file reached, frc=%d sid=%d) ...", (
int) btord, (
int) frc, sion_filedesc->
sid));
938 DPRINTFP((2, DFUNCTION, -1,
"leave rc=%d\n",rc));
944 #define DFUNCTION "_sion_keyval_dup_dataptr_inline"
950 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
957 keymngr =_sion_keyvalue_keymngr_dup(keymngr_orig,new_filedesc->
dup_mode, new_filedesc->
dup_sel_key);
958 if (keymngr == NULL) {
959 return(_sion_errorprint_on_rank(-1,_SION_ERROR_RETURN,sion_filedesc->
rank,
"dup: could not duplicate keymngr ..."));
969 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
void sion_swap(void *target, void *source, int size, int n, int do_swap)
sion_int64 _sion_file_set_position(_sion_fileptr *sion_fileptr, sion_int64 startpointer)
Set new position in file.
int _sion_file_purge(_sion_fileptr *sion_fileptr)
Purge data to file.
sion_int64 _sion_file_write(const void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr)
Write data to file.
sion_int64 _sion_file_read(void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr)
Read data from file.
int _sion_create_new_block(_sion_filedesc *sion_filedesc)
Create a new block for the internal data structure.
int _sion_flush_block(_sion_filedesc *sion_filedesc)
Update the internal data structure.
Sion File Descriptor Structure.
sion_int32 currentblocknr