Newer
Older
{
void *m_data;
CUDAPP_CALL_GUARDED(cuMemAllocHost, (&m_data, size));
return m_data;
}
inline void mem_free_host(void *ptr)
{
CUDAPP_CALL_GUARDED(cuMemFreeHost, (ptr));
}
struct host_allocation : public boost::noncopyable
{
private:
void *m_data;
public:
host_allocation(unsigned bytesize)
: m_data(mem_alloc_host(bytesize))
{ }
~host_allocation()
{ free(); }
void free()
{
if (m_data)
{
mem_free_host(m_data);
m_data = 0;
}
}
void *data()
{ return m_data; }
};
// events -------------------------------------------------------------------
class event : public boost::noncopyable, public context_dependent
{
private:
CUevent m_event;
public:
event(unsigned int flags=0)
{ CUDAPP_CALL_GUARDED(cuEventCreate, (&m_event, flags)); }
~event()
{
scoped_context_activation ca(get_context());
CUDAPP_CALL_GUARDED(cuEventDestroy, (m_event));
}
void record()
{ CUDAPP_CALL_GUARDED(cuEventRecord, (m_event, 0)); }
void record_in_stream(stream const &str)
{ CUDAPP_CALL_GUARDED(cuEventRecord, (m_event, str.handle())); }
void synchronize()
{ CUDAPP_CALL_GUARDED_THREADED(cuEventSynchronize, (m_event)); }
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
bool query() const
{
#ifdef TRACE_CUDA
std::cerr << "cuEventQuery" << std::endl;
#endif
CUresult result = cuEventQuery(m_event);
switch (result)
{
case CUDA_SUCCESS:
return true;
case CUDA_ERROR_NOT_READY:
return false;
default:
throw error("cuEventQuery", result);
}
}
float time_since(event const &start)
{
float result;
CUDAPP_CALL_GUARDED(cuEventElapsedTime, (&result, start.m_event, m_event));
return result;
}
float time_till(event const &end)
{
float result;
CUDAPP_CALL_GUARDED(cuEventElapsedTime, (&result, m_event, end.m_event));
return result;
}
};
}
#endif