9 #define _XOPEN_SOURCE 700
17 #include <sys/types.h>
23 #include <cuda_runtime.h>
28 #include "sion_error_handler.h"
33 #if defined(_SION_LINUX)
34 #elif defined(_SION_AIX)
35 #elif defined(_SION_BGP)
53 #define DFUNCTION "_sion_buffer_check_env"
62 int rc = SION_SUCCESS;
68 DPRINTFP((2, DFUNCTION, -1,
"buffersize=%d\n", sion_filedesc->
buffer_size));
74 #define DFUNCTION "_sion_buffer_init"
82 int rc = SION_SUCCESS;
87 if (sion_filedesc->
buffer == NULL) {
88 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_buffer_init: cannot allocate internal buffer of size %lu , aborting ...\n", (
unsigned long) sion_filedesc->
buffer_size));
91 DPRINTFP((2, DFUNCTION, -1,
"buffer with size=%d allocated\n", sion_filedesc->
buffer_size));
97 #define DFUNCTION "_sion_buffer_push"
107 const void *data, sion_int64 bytes) {
108 sion_int64 bytes_free;
109 sion_int64 bytes_stored;
110 ONLY_DEBUG(sion_int64 bytes_not_stored;)
113 if(bytes<bytes_free) {
115 ONLY_DEBUG(bytes_not_stored=0;)
117 bytes_stored=bytes_free;
118 ONLY_DEBUG(bytes_not_stored=bytes-bytes_stored;)
122 struct cudaPointerAttributes attrs;
123 cudaError_t err = cudaPointerGetAttributes(&attrs, data);
124 if ((err == cudaSuccess) && _sion_cuda_ptr_is_device(attrs) ) {
125 cudaMemcpy(sion_filedesc->
buffer + sion_filedesc->
buffer_ptr, data, bytes_stored, cudaMemcpyDeviceToHost);
135 DPRINTFP((2, DFUNCTION, -1,
"pushed %d of %d bytes into buffer -> ptr=%d ret=%d\n",
136 (
int) bytes_stored,(
int) bytes,
137 (
int) sion_filedesc->
buffer_ptr, (
int) bytes_not_stored));
138 return (bytes_stored);
142 #define DFUNCTION "_sion_buffer_get_data_ptr"
153 void **data, sion_int64 *bytes) {
157 *data=sion_filedesc->
buffer;
163 DPRINTFP((2, DFUNCTION, -1,
"returns data ptr to %d bytes, flag=%d\n",
164 (
int) *bytes, flag));
170 #define DFUNCTION "_sion_buffer_flush"
178 sion_int64 bbytes, frc, byteswritten;
182 DPRINTFP((1, DFUNCTION, -1,
"enter\n"));
190 if ((byteswritten + bbytes) > sion_filedesc->
chunksize) {
197 return(_sion_errorprint_on_rank(SION_ANSI_SIZE_NOT_VALID,_SION_ERROR_RETURN,sion_filedesc->
rank,
198 "could not write data (%d bytes) to file (sid=%d) ...", (
int) bbytes, sion_filedesc->
sid));
202 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
204 return (SION_SUCCESS);
int _sion_buffer_check_env(_sion_filedesc *sion_filedesc)
Checks if environment variables are set to use buffer.
int _sion_buffer_get_data_ptr(_sion_filedesc *sion_filedesc, void **data, sion_int64 *bytes)
Pop all data from buffer.
int _sion_buffer_init(_sion_filedesc *sion_filedesc)
Allocate and initalize the buffer.
int _sion_buffer_flush(_sion_filedesc *sion_filedesc)
Flush buffer.
sion_int64 _sion_buffer_push(_sion_filedesc *sion_filedesc, const void *data, sion_int64 bytes)
Push data to buffer.
sion_int64 _sion_file_write(const void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr)
Write data to file.
int _sion_create_new_block(_sion_filedesc *sion_filedesc)
Create a new block for the internal data structure.
char * _sion_getenv(const char *name)
int _sion_flush_block(_sion_filedesc *sion_filedesc)
Update the internal data structure.
Sion File Descriptor Structure.
sion_int32 currentblocknr