milk  1.01
Modular Image processing Library toolKit
ImageStruct.h
Go to the documentation of this file.
1 
18 #ifndef _IMAGESTRUCT_H
19 #define _IMAGESTRUCT_H
20 
21 #define IMAGESTRUCT_VERSION "1.01"
22 
23 #define STRINGMAXLEN_IMAGE_NAME 80
24 #define KEYWORD_MAX_STRING 16
25 #define KEYWORD_MAX_COMMENT 80
30 #include <semaphore.h>
31 #include <stdint.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <sys/types.h>
35 #include <unistd.h>
36 #include <time.h> // TEST
37 
38 #ifdef HAVE_CUDA
39 // CUDA runtime includes
40 #include <cuda_runtime_api.h>
41 #else
42 // CUDA cudaIpcMemHandle_t is a struct of 64 bytes
43 // This is needed for for compatibility between ImageStreamIO
44 // compiled with or without HAVE_CUDA precompiler flag
45 typedef char cudaIpcMemHandle_t[64];
46 #endif
47 
48 #include "ImageStreamIOError.h"
49 
50 #ifdef __MACH__
51 #include <mach/mach_time.h>
52 #define CLOCK_REALTIME 0
53 #define CLOCK_MONOTONIC 0
54 static int clock_gettime(int clk_id, struct mach_timespec *t) {
55  mach_timebase_info_data_t timebase;
56  mach_timebase_info(&timebase);
57  uint64_t time;
58  time = mach_absolute_time();
59  double nseconds =
60  ((double)time * (double)timebase.numer) / ((double)timebase.denom);
61  double seconds =
62  ((double)time * (double)timebase.numer) / ((double)timebase.denom * 1e9);
63  t->tv_sec = seconds;
64  t->tv_nsec = nseconds;
65  return EXIT_SUCCESS;
66 }
67 #else
68 #include <time.h>
69 #endif
70 
71 #ifdef __cplusplus
72 extern "C" {
73 #endif
74 
75 // comment this line if data should not be packed
76 // packing data should be use with extreme care, so it is recommended to disable this feature
77 //#define DATA_PACKED
78 
79 #define SHAREDMEMDIR "/milk/shm"
81 #define SEMAPHORE_MAXVAL 10
82 #define SEMAPHORE_INITVAL 0
83 #define IMAGE_NB_SEMAPHORE 10
85 #define IMAGE_NB_PROCTRACE 10
87 // Data types are defined as machine-independent types for portability
88 
89 #define _DATATYPE_UINT8 1
90 #define SIZEOF_DATATYPE_UINT8 1
91 
92 #define _DATATYPE_INT8 2
93 #define SIZEOF_DATATYPE_INT8 1
94 
95 #define _DATATYPE_UINT16 3
96 #define SIZEOF_DATATYPE_UINT16 2
97 
98 #define _DATATYPE_INT16 4
99 #define SIZEOF_DATATYPE_INT16 2
100 
101 #define _DATATYPE_UINT32 5
102 #define SIZEOF_DATATYPE_UINT32 4
103 
104 #define _DATATYPE_INT32 6
105 #define SIZEOF_DATATYPE_INT32 4
106 
107 #define _DATATYPE_UINT64 7
108 #define SIZEOF_DATATYPE_UINT64 8
109 
110 #define _DATATYPE_INT64 8
111 #define SIZEOF_DATATYPE_INT64 8
112 
113 #define _DATATYPE_HALF 13
114 #define SIZEOF_DATATYPE_HALF 2
115 
116 #define _DATATYPE_FLOAT 9
117 #define SIZEOF_DATATYPE_FLOAT 4
118 
119 #define _DATATYPE_DOUBLE 10
120 #define SIZEOF_DATATYPE_DOUBLE 8
121 
122 #define _DATATYPE_COMPLEX_FLOAT 11
123 #define SIZEOF_DATATYPE_COMPLEX_FLOAT 8
124 
125 #define _DATATYPE_COMPLEX_DOUBLE 12
126 #define SIZEOF_DATATYPE_COMPLEX_DOUBLE 16
127 
128 #define _DATATYPE_EVENT_UI8_UI8_UI16_UI8 20
129 #define SIZEOF_DATATYPE_EVENT_UI8_UI8_UI16_UI8 5
130 
131 #define Dtype 9
132 #define CDtype 11
134 // Type of stream
135 
136 #define CIRCULAR_BUFFER 0x0001
137 #define MATH_DATA 0x0002
138 #define IMG_RECV 0x0004
139 #define IMG_SENT 0x0008
141 // axis0 definition
142 
143 #define ZAXIS_UNDEF 0x00000
144 #define ZAXIS_SPACIAL 0x10000
145 #define ZAXIS_TEMPORAL 0x20000
146 #define ZAXIS_WAVELENGTH 0x30000
147 #define ZAXIS_MAPPING 0x40000
155 typedef struct {
156  char name[KEYWORD_MAX_STRING];
157  char type;
158  uint64_t : 0; // align array to 8-byte boundary for speed
159 
160  union {
161  int64_t numl;
162  double numf;
163  char valstr[KEYWORD_MAX_STRING];
164  } value;
165 
166  char comment[KEYWORD_MAX_COMMENT];
167 #ifdef DATA_PACKED
168 } __attribute__((__packed__)) IMAGE_KEYWORD;
169 #else
170 } IMAGE_KEYWORD;
171 #endif
172 
177 typedef struct {
178  int64_t firstlong;
179  int64_t secondlong;
180 } TIMESPECFIXED;
181 
182 typedef struct {
183  float re;
184  float im;
185 } complex_float;
186 
187 typedef struct {
188  double re;
189  double im;
191 
192 
193 
194 
200 typedef struct
201 {
202  char version[32];
212  char name[STRINGMAXLEN_IMAGE_NAME];
213 
214 
219  uint8_t naxis;
220 
221 
226  uint32_t size[3];
227 
228 
233  uint64_t nelement;
234 
235 
236 
255  uint8_t datatype;
256 
257 
258 
259 
260 
261  uint64_t imagetype;
282  // relative timers using time relative to process start
283 
284  // double creationtime; /**< Creation / load time of data structure (since process start) */
285  // double lastaccesstime; /**< last time the image was accessed (since process start) */
286 
287 
288 
289  // absolute timers using struct timespec
290 
291  struct timespec creationtime;
292  struct timespec lastaccesstime;
293 
294  struct timespec atime;
295  struct timespec writetime;
298  pid_t creatorPID;
300  pid_t ownerPID;
301  /* May be used to purge stream(s) when a process is completed/dead */
302  /* Initialized to 0 */
303  /* Set to 1 to indicate the stream does not belong to a process */
304 
305 
306  uint8_t shared;
307  ino_t inode;
308  int8_t location;
309  uint8_t status;
310  uint64_t flag;
312  uint8_t logflag;
313  uint16_t sem;
314  uint16_t NBproctrace;
317  uint64_t : 0; // align array to 8-byte boundary for speed
318 
319  uint64_t cnt0;
320  uint64_t cnt1;
321  uint64_t cnt2;
323  uint8_t write;
326  uint16_t NBkw;
328  cudaIpcMemHandle_t cudaMemHandle;
329 
330 #ifdef DATA_PACKED
331 } __attribute__((__packed__)) IMAGE_METADATA;
332 #else
334 #endif
335 
336 
337 
345 typedef struct
346 {
347  int triggermode;
350  struct timespec ts_procstart;
351  struct timespec ts_streamupdate;
353  int triggerstatus;
354  uint64_t cnt0;
356 
357 
358 
366 typedef struct
367 {
368  char name[STRINGMAXLEN_IMAGE_NAME];
378  uint8_t used;
379 
380  int32_t shmfd;
382  uint64_t memsize;
384  sem_t *semlog;
386  IMAGE_METADATA *md;
387 
388 
389  uint64_t : 0; // align array to 8-byte boundary for speed
390 
403  union {
404  void *raw; // raw pointer
405 
406  uint8_t *UI8; // char
407  int8_t *SI8;
408 
409  uint16_t *UI16; // unsigned short
410  int16_t *SI16;
411 
412  uint32_t *UI32;
413  int32_t *SI32; // int
414 
415  uint64_t *UI64;
416  int64_t *SI64; // long
417 
418  float *F;
419  double *D;
420 
421  complex_float *CF;
422  complex_double *CD;
423 
424  } array;
427  // Semaphores
428 
429  sem_t **semptr;
431  IMAGE_KEYWORD *kw;
432 
433 
434  // PID of process that read shared memory stream
435  // Initialized at 0. Otherwise, when process is waiting on semaphore, its PID is written in this array
436  // The array can be used to look for available semaphores
437  pid_t *semReadPID;
438 
439  // PID of the process posting the semaphores
440  pid_t *semWritePID;
441 
442  // array
443  // keeps track of stream history/depedencies
444  STREAM_PROC_TRACE *streamproctrace;
445 
446 
447  uint64_t *flagarray;
448  uint64_t *cntarray;
449  struct timespec *atimearray;
450  struct timespec *writetimearray;
452 #ifdef DATA_PACKED
453 } __attribute__((__packed__)) IMAGE;
454 #else
455 } IMAGE;
456 #endif
457 
458 #ifdef __cplusplus
459 } // extern "C"
460 #endif
461 
462 #endif
IMAGE_METADATA::naxis
uint8_t naxis
Number of axis.
Definition: ImageStruct.h:219
IMAGE::used
uint8_t used
Image usage flag.
Definition: ImageStruct.h:378
complex_float
Definition: ImageStruct.h:182
KEYWORD_MAX_COMMENT
#define KEYWORD_MAX_COMMENT
Definition: ImageStruct.h:25
IMAGE_METADATA::shared
uint8_t shared
Definition: ImageStruct.h:306
IMAGE_METADATA::cnt2
uint64_t cnt2
Definition: ImageStruct.h:321
IMAGE::atimearray
struct timespec * atimearray
Definition: ImageStruct.h:449
IMAGE_METADATA::cnt0
uint64_t cnt0
Definition: ImageStruct.h:319
IMAGE_METADATA
Image metadata.
Definition: ImageStruct.h:200
IMAGE_METADATA::sem
uint16_t sem
Definition: ImageStruct.h:313
IMAGE_METADATA::cnt1
uint64_t cnt1
Definition: ImageStruct.h:320
IMAGE
IMAGE structure The IMAGE structure includes :
Definition: ImageStruct.h:366
TIMESPECFIXED
structure holding two 8-byte integers
Definition: ImageStruct.h:177
IMAGE::memsize
uint64_t memsize
Definition: ImageStruct.h:382
IMAGE_KEYWORD::type
char type
Definition: ImageStruct.h:157
IMAGE_METADATA::flag
uint64_t flag
Definition: ImageStruct.h:310
STREAM_PROC_TRACE
STREAM_PROC_TRACE holds trigger and timing info.
Definition: ImageStruct.h:345
IMAGE_METADATA::write
uint8_t write
Definition: ImageStruct.h:323
IMAGE::semptr
sem_t ** semptr
Definition: ImageStruct.h:429
complex_double
Definition: ImageStruct.h:187
IMAGE_METADATA::logflag
uint8_t logflag
Definition: ImageStruct.h:312
IMAGE_METADATA::NBproctrace
uint16_t NBproctrace
Definition: ImageStruct.h:314
IMAGE::cntarray
uint64_t * cntarray
Definition: ImageStruct.h:448
IMAGE_METADATA::location
int8_t location
Definition: ImageStruct.h:308
IMAGE_METADATA::creatorPID
pid_t creatorPID
Definition: ImageStruct.h:298
IMAGE::shmfd
int32_t shmfd
Definition: ImageStruct.h:380
IMAGE::semlog
sem_t * semlog
Definition: ImageStruct.h:384
IMAGE_METADATA::status
uint8_t status
Definition: ImageStruct.h:309
KEYWORD_MAX_STRING
#define KEYWORD_MAX_STRING
Definition: ImageStruct.h:24
IMAGE_KEYWORD
Keyword The IMAGE_KEYWORD structure includes :
Definition: ImageStruct.h:155
STREAM_PROC_TRACE::cnt0
uint64_t cnt0
Definition: ImageStruct.h:354
IMAGE_METADATA::datatype
uint8_t datatype
Data type.
Definition: ImageStruct.h:255
__attribute__
errno_t __attribute__((hot))
Logs a shared memory stream onto disk.
Definition: logshmim.c:685
IMAGE_METADATA::NBkw
uint16_t NBkw
Definition: ImageStruct.h:326
IMAGE::flagarray
uint64_t * flagarray
Definition: ImageStruct.h:447
STREAM_PROC_TRACE::trigger_inode
ino_t trigger_inode
Definition: ImageStruct.h:349
IMAGE::writetimearray
struct timespec * writetimearray
Definition: ImageStruct.h:450
IMAGE_METADATA::inode
ino_t inode
Definition: ImageStruct.h:307
STREAM_PROC_TRACE::trigsemindex
int trigsemindex
Definition: ImageStruct.h:352
STREAM_PROC_TRACE::procwrite_PID
pid_t procwrite_PID
Definition: ImageStruct.h:348
IMAGE_METADATA::ownerPID
pid_t ownerPID
Definition: ImageStruct.h:300
IMAGE_METADATA::imagetype
uint64_t imagetype
Definition: ImageStruct.h:261
IMAGE_METADATA::nelement
uint64_t nelement
Number of elements in image.
Definition: ImageStruct.h:233