27 #ifndef bits_gpulog_logrecord_h__
28 #define bits_gpulog_logrecord_h__
47 __host__ __device__
inline const arginfo &get_arginfo(
int arg)
const {
return *((
arginfo *)(ptr +
hdr().infos) + arg); }
51 __host__ __device__
inline logrecord() : ptr(NULL), at(0) { IFARGINFO(atarg = 1); }
53 __host__ __device__
inline logrecord(
const char *ptr_) : ptr(ptr_), at(
hdr().dataoffset()) { IFARGINFO(atarg = 1); }
58 __host__ __device__
inline operator bool()
const {
return at <
hdr().
len; }
61 __host__ __device__
inline int len()
const {
return hdr().
len; }
63 __host__ __device__
inline int msgid()
const {
return hdr().
msgid; }
67 typedef logrecord& logrecord_ref;
70 __device__
void assert_arg_compatible(logrecord &in, T &v)
72 #if ARGINFO && !__CUDACC__
73 const arginfo &ai = in.get_arginfo(in.atarg);
76 DHOST( std::cerr <<
" Log : " << ai <<
"\n"; )
77 DHOST( std::cerr <<
" Host : arg=" << in.atarg <<
" align=" << TT::align <<
" size=" << TT::size <<
" dim=" << TT::dim <<
" isptr=" << TT::isptr <<
"\n"; )
79 #define AITEST(a, TT, b) \
82 std::cerr << "Assertion failed GPUTypeTraits::" #a " != HostTypeTraits::" #b << " (" << a << " != " << TT::b << ")\n"; \
83 std::cerr << " Log : " << ai << "\n"; \
84 std::cerr << " Host : arg=" << in.atarg << " align=" << TT::align << " size=" << TT::size << " dim=" << TT::dim << " isptr=" << TT::isptr << "\n"; \
91 AITEST( ai.align, TT, align );
92 AITEST( ai.size, TT, size );
95 if(in.atarg+1 < in.hdr().nargs) { in.atarg++; }
101 __device__
inline logrecord_ref operator >>(logrecord &in, T &v)
103 if(!in) {
return in; }
107 in.at = offs +
sizeof(T);
108 assert_arg_compatible(in, v);
109 dev_assert(in.at <= in.len());
111 v = *(T*)(in.ptr + offs);
113 DHOST( std::cerr <<
"reading scalar POD: offs = " << offs <<
" val = " << v <<
"\n"; )
119 template<
typename T,
int N>
120 __device__
inline logrecord_ref operator >>(logrecord &in,
const T (&v)[N])
122 if(!in) {
return in; }
126 in.at = offs +
sizeof(T)*N;
127 assert_arg_compatible(in, v);
128 dev_assert(in.at <= in.len());
130 for(
int i = 0; i != N; i++)
132 v[i] = ((T*)(in.ptr + offs))[i];
133 DHOST( std::cerr <<
"reading array: offs = " << offs <<
" N = " << N <<
" val[" << i <<
"] = " << v[i] <<
"\n"; )
140 __device__
inline logrecord_ref operator>>(logrecord &in,
char *v)
142 if(!in) {
return in; }
145 DHOST(
char *v0 = v;
int offs = in.at; )
146 assert_arg_compatible(in, v);
149 *v = in.ptr[in.at++];
154 dev_assert(in.at <= in.len());
156 DHOST( std::cerr <<
"reading character string: offs = " << offs <<
" val = " << v0 <<
" endoff = " << in.at <<
"\n"; )
162 __device__ inline logrecord_ref operator>>(logrecord &in,
char v[N])
164 return in >> (
char *)v;
169 __device__
inline logrecord_ref operator >>(logrecord &in, T *&v)
174 STATIC_ASSERTION_FAILED__Your_pointer_must_be_to_const_T_and_not_just_T______(v);
180 __device__
inline logrecord_ref operator >>(logrecord &in,
const T *&v)
182 if(!in) {
return in; }
186 assert_arg_compatible(in, v);
187 v = (
const T*)(in.ptr + offs);
188 in.at = in.hdr().len;
190 DHOST( std::cerr <<
"reading unbound array : offs = " << offs <<
" v = " << (
void*)v <<
" v[0] = " << *v <<
"\n"; )
191 DHOST( std::cerr << (
char*)v - in.ptr <<
"\n"; )
199 #endif // bits_gpulog_logrecord_h__