X-Git-Url: http://www.fmaj7b5.info/git?p=cuda.git;a=blobdiff_plain;f=libutils%2Fcuda%2FEvent.h;fp=libutils%2Fcuda%2FEvent.h;h=a1b2b14ade89087f1f49a892cf4206f1f3417d67;hp=0000000000000000000000000000000000000000;hb=e4a0dfee97228c4e3af62199e692b8fe6018939d;hpb=18d89446c09d0c5608b49aae12558542cc869ec3
diff --git a/libutils/cuda/Event.h b/libutils/cuda/Event.h
new file mode 100644
index 0000000..a1b2b14
--- /dev/null
+++ b/libutils/cuda/Event.h
@@ -0,0 +1,97 @@
+/*
+ Copyright (C) 2012, 2013 fmaj7b5.info
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+*/
+
+#ifndef FM7b5_CUDA_EVENT_H
+#define FM7b5_CUDA_EVENT_H
+
+#include
+#include
+
+class Event
+{
+public:
+ Event();
+ Event(unsigned int flags);
+ ~Event();
+ operator cudaEvent_t();
+
+ cudaError_t query() const;
+ cudaError_t record(cudaStream_t stream = (cudaStream_t)0) const;
+ cudaError_t synchronize() const;
+
+protected:
+ cudaEvent_t m_event;
+};
+
+
+Event::Event()
+{
+ cudaError_t status;
+
+ status = cudaEventCreate(&m_event);
+
+ if (status != cudaSuccess) {
+ throw std::runtime_error(cudaGetErrorString(status));
+ }
+}
+
+Event::Event(unsigned int flags)
+{
+ cudaError_t status;
+
+ status = cudaEventCreateWithFlags(&m_event, flags);
+
+ if (status != cudaSuccess) {
+ throw std::runtime_error(cudaGetErrorString(status));
+ }
+}
+
+Event::~Event()
+{
+ cudaError_t status;
+
+ status = cudaEventDestroy(m_event);
+
+ if (status != cudaSuccess) {
+ throw std::runtime_error(cudaGetErrorString(status));
+ }
+}
+
+Event::operator cudaEvent_t()
+{
+ return m_event;
+}
+
+cudaError_t
+Event::query() const
+{
+ return cudaEventQuery(m_event);
+}
+
+cudaError_t
+Event::record(cudaStream_t stream) const
+{
+ return cudaEventRecord(m_event, stream);
+}
+
+cudaError_t
+Event::synchronize() const
+{
+ return cudaEventSynchronize(m_event);
+}
+
+#endif /* FM7b5_CUDA_EVENT_H */