cacao  Release 0.1.03-dev
Compute And Control For Adaptive Optics
ImageStruct.h
Go to the documentation of this file.
1 
18 #ifndef _IMAGESTRUCT_H
19 #define _IMAGESTRUCT_H
20 
21 #define IMAGESTRUCT_VERSION "0.0.01"
22 
23 #include <semaphore.h>
24 #include <stdint.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <sys/types.h>
28 #include <unistd.h>
29 #include <time.h> // TEST
30 
31 #ifdef HAVE_CUDA
32 // CUDA runtime includes
33 #include <cuda_runtime_api.h>
34 #else
35 // CUDA cudaIpcMemHandle_t is a struct of 64 bytes
36 // This is needed for for compatibility between ImageStreamIO
37 // compiled with or without HAVE_CUDA precompiler flag
38 typedef char cudaIpcMemHandle_t[64];
39 #endif
40 
41 #include "ImageStreamIOError.h"
42 
43 #ifdef __MACH__
44 #include <mach/mach_time.h>
45 #define CLOCK_REALTIME 0
46 #define CLOCK_MONOTONIC 0
47 static int clock_gettime(int clk_id, struct mach_timespec *t) {
48  mach_timebase_info_data_t timebase;
49  mach_timebase_info(&timebase);
50  uint64_t time;
51  time = mach_absolute_time();
52  double nseconds =
53  ((double)time * (double)timebase.numer) / ((double)timebase.denom);
54  double seconds =
55  ((double)time * (double)timebase.numer) / ((double)timebase.denom * 1e9);
56  t->tv_sec = seconds;
57  t->tv_nsec = nseconds;
58  return EXIT_SUCCESS;
59 }
60 #else
61 #include <time.h>
62 #endif
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 // comment this line if data should not be packed
69 // packing data should be use with extreme care, so it is recommended to disable this feature
70 //#define DATA_PACKED
71 
72 #define SHAREDMEMDIR "/milk/shm"
74 #define SEMAPHORE_MAXVAL 10
75 #define SEMAPHORE_INITVAL 0
76 #define IMAGE_NB_SEMAPHORE 10
78 // Data types are defined as machine-independent types for portability
79 
80 #define _DATATYPE_UINT8 1
81 #define SIZEOF_DATATYPE_UINT8 1
82 
83 #define _DATATYPE_INT8 2
84 #define SIZEOF_DATATYPE_INT8 1
85 
86 #define _DATATYPE_UINT16 3
87 #define SIZEOF_DATATYPE_UINT16 2
88 
89 #define _DATATYPE_INT16 4
90 #define SIZEOF_DATATYPE_INT16 2
91 
92 #define _DATATYPE_UINT32 5
93 #define SIZEOF_DATATYPE_UINT32 4
94 
95 #define _DATATYPE_INT32 6
96 #define SIZEOF_DATATYPE_INT32 4
97 
98 #define _DATATYPE_UINT64 7
99 #define SIZEOF_DATATYPE_UINT64 8
100 
101 #define _DATATYPE_INT64 8
102 #define SIZEOF_DATATYPE_INT64 8
103 
104 #define _DATATYPE_HALF 13
105 #define SIZEOF_DATATYPE_HALF 2
106 
107 #define _DATATYPE_FLOAT 9
108 #define SIZEOF_DATATYPE_FLOAT 4
109 
110 #define _DATATYPE_DOUBLE 10
111 #define SIZEOF_DATATYPE_DOUBLE 8
112 
113 #define _DATATYPE_COMPLEX_FLOAT 11
114 #define SIZEOF_DATATYPE_COMPLEX_FLOAT 8
115 
116 #define _DATATYPE_COMPLEX_DOUBLE 12
117 #define SIZEOF_DATATYPE_COMPLEX_DOUBLE 16
118 
119 #define _DATATYPE_EVENT_UI8_UI8_UI16_UI8 20
120 #define SIZEOF_DATATYPE_EVENT_UI8_UI8_UI16_UI8 5
121 
122 #define Dtype 9
123 #define CDtype 11
125 // Type of stream
126 
127 #define CIRCULAR_BUFFER 0x0001
128 #define MATH_DATA 0x0002
129 #define IMG_RECV 0x0004
130 #define IMG_SENT 0x0008
132 // axis0 definition
133 
134 #define ZAXIS_UNDEF 0x00000
135 #define ZAXIS_SPACIAL 0x10000
136 #define ZAXIS_TEMPORAL 0x20000
137 #define ZAXIS_WAVELENGTH 0x30000
138 #define ZAXIS_MAPPING 0x40000
146 typedef struct {
147  char name[16];
148  char type;
149  uint64_t : 0; // align array to 8-byte boundary for speed
150 
151  union {
152  int64_t numl;
153  double numf;
154  char valstr[16];
155  } value;
156 
157  char comment[80];
158 #ifdef DATA_PACKED
159 } __attribute__((__packed__)) IMAGE_KEYWORD;
160 #else
161 } IMAGE_KEYWORD;
162 #endif
163 
168 typedef struct {
169  int64_t firstlong;
170  int64_t secondlong;
171 } TIMESPECFIXED;
172 
173 typedef struct {
174  float re;
175  float im;
176 } complex_float;
177 
178 typedef struct {
179  double re;
180  double im;
182 
183 
184 
185 
191 typedef struct
192 {
193  char version[32];
203  char name[80];
204 
205 
210  uint8_t naxis;
211 
212 
217  uint32_t size[3];
218 
219 
224  uint64_t nelement;
225 
226 
227 
246  uint8_t datatype;
247 
248 
249 
250 
251 
252  uint64_t imagetype;
273  // relative timers using time relative to process start
274 
275  // double creationtime; /**< Creation / load time of data structure (since process start) */
276  // double lastaccesstime; /**< last time the image was accessed (since process start) */
277 
278 
279 
280  // absolute timers using struct timespec
281 
282  struct timespec creationtime;
283  struct timespec lastaccesstime;
284 
285  struct timespec atime;
286  struct timespec writetime;
291  uint8_t shared;
292  int8_t location;
293  uint8_t status;
294  uint64_t flag;
296  uint8_t logflag;
297  uint16_t sem;
300  uint64_t : 0; // align array to 8-byte boundary for speed
301 
302  uint64_t cnt0;
303  uint64_t cnt1;
304  uint64_t cnt2;
306  uint8_t write;
310  uint16_t NBkw;
313 
314 #ifdef DATA_PACKED
315 } __attribute__((__packed__)) IMAGE_METADATA;
316 #else
318 #endif
319 
320 
321 
322 
330 typedef struct
331 {
332  char name[80];
333  // mem offset = 80
334 
343  uint8_t used;
344 
345  int32_t shmfd;
347  uint64_t memsize;
349  sem_t *semlog;
352 
353 
354  uint64_t : 0; // align array to 8-byte boundary for speed
355 
368  union {
369  void *raw; // raw pointer
370 
371  uint8_t *UI8; // char
372  int8_t *SI8;
373 
374  uint16_t *UI16; // unsigned short
375  int16_t *SI16;
376 
377  uint32_t *UI32;
378  int32_t *SI32; // int
379 
380  uint64_t *UI64;
381  int64_t *SI64; // long
382 
383  float *F;
384  double *D;
385 
388 
389  } array;
392  sem_t **semptr;
395 
396  // PID of process that read shared memory stream
397  // Initialized at 0. Otherwise, when process is waiting on semaphore, its PID is written in this array
398  // The array can be used to look for available semaphores
399  pid_t *semReadPID;
400 
401  // PID of the process writing the data
402  pid_t *semWritePID;
403 
404  uint64_t *flagarray;
405  uint64_t *cntarray;
406  struct timespec *atimearray;
407  struct timespec *writetimearray;
409  // total size is 152 byte = 1216 bit
410 #ifdef DATA_PACKED
411 } __attribute__((__packed__)) IMAGE;
412 #else
413 } IMAGE;
414 #endif
415 
416 #ifdef __cplusplus
417 } // extern "C"
418 #endif
419 
420 #endif
int8_t * SI8
Definition: ImageStruct.h:372
int64_t firstlong
Definition: ImageStruct.h:169
int32_t * SI32
Definition: ImageStruct.h:378
int16_t * SI16
Definition: ImageStruct.h:375
uint16_t NBkw
Definition: ImageStruct.h:310
double * D
Definition: ImageStruct.h:384
int64_t numl
Definition: ImageStruct.h:152
uint8_t status
Definition: ImageStruct.h:293
IMAGE structure The IMAGE structure includes :
Definition: ImageStruct.h:330
structure holding two 8-byte integers
Definition: ImageStruct.h:168
sem_t ** semptr
Definition: ImageStruct.h:392
uint64_t cnt0
Definition: ImageStruct.h:302
float im
Definition: ImageStruct.h:175
uint64_t cnt1
Definition: ImageStruct.h:303
void * raw
Definition: ImageStruct.h:369
cudaIpcMemHandle_t cudaMemHandle
Definition: ImageStruct.h:312
uint8_t naxis
Number of axis.
Definition: ImageStruct.h:210
IMAGE_KEYWORD * kw
Definition: ImageStruct.h:394
uint64_t * UI64
Definition: ImageStruct.h:380
uint64_t nelement
Number of elements in image.
Definition: ImageStruct.h:224
Keyword The IMAGE_KEYWORD structure includes :
Definition: ImageStruct.h:146
uint8_t datatype
Data type.
Definition: ImageStruct.h:246
Definition: ImageStruct.h:178
Image metadata.
Definition: ImageStruct.h:191
void __attribute__((constructor)) libinit_00CORE()
Definition: ImageStreamIO.c:77
float re
Definition: ImageStruct.h:174
uint64_t cnt2
Definition: ImageStruct.h:304
uint8_t write
Definition: ImageStruct.h:306
int32_t shmfd
Definition: ImageStruct.h:345
uint64_t flag
Definition: ImageStruct.h:294
complex_float * CF
Definition: ImageStruct.h:386
uint8_t logflag
Definition: ImageStruct.h:296
int64_t * SI64
Definition: ImageStruct.h:381
struct timespec * writetimearray
Definition: ImageStruct.h:407
double im
Definition: ImageStruct.h:180
pid_t * semReadPID
Definition: ImageStruct.h:399
int8_t location
Definition: ImageStruct.h:292
struct timespec * atimearray
Definition: ImageStruct.h:406
uint8_t shared
Definition: ImageStruct.h:291
uint64_t imagetype
Definition: ImageStruct.h:252
pid_t * semWritePID
Definition: ImageStruct.h:402
uint16_t sem
Definition: ImageStruct.h:297
double re
Definition: ImageStruct.h:179
double numf
Definition: ImageStruct.h:153
IMAGE_METADATA * md
Definition: ImageStruct.h:351
uint8_t * UI8
Definition: ImageStruct.h:371
uint64_t memsize
Definition: ImageStruct.h:347
uint32_t * UI32
Definition: ImageStruct.h:377
sem_t * semlog
Definition: ImageStruct.h:349
uint16_t * UI16
Definition: ImageStruct.h:374
uint64_t * flagarray
Definition: ImageStruct.h:404
char type
Definition: ImageStruct.h:148
float * F
Definition: ImageStruct.h:383
uint64_t * cntarray
Definition: ImageStruct.h:405
uint8_t used
Image usage flag.
Definition: ImageStruct.h:343
Definition: ImageStruct.h:173
char cudaIpcMemHandle_t[64]
Definition: ImageStruct.h:38
complex_double * CD
Definition: ImageStruct.h:387
int64_t secondlong
Definition: ImageStruct.h:170