From e4a0dfee97228c4e3af62199e692b8fe6018939d Mon Sep 17 00:00:00 2001 From: dev Date: Sun, 30 Jun 2013 00:58:25 +0900 Subject: [PATCH] =?utf8?q?cudaEvent=5Ft=E3=81=A8cudaStream=5Ft=E3=81=AE=E3=83?= =?utf8?q?=A9=E3=83=83=E3=83=91=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- libutils/cuda/Event.h | 97 +++++++++++++++++++++++++++++++++++++++ libutils/cuda/Stream.h | 85 ++++++++++++++++++++++++++++++++++ libutils/cuda/cuda_wrapper.h | 28 +++++++++++ libutils/libutils.vcxproj | 5 ++ libutils/libutils.vcxproj.filters | 12 +++++ 5 files changed, 227 insertions(+) create mode 100644 libutils/cuda/Event.h create mode 100644 libutils/cuda/Stream.h create mode 100644 libutils/cuda/cuda_wrapper.h 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 */ diff --git a/libutils/cuda/Stream.h b/libutils/cuda/Stream.h new file mode 100644 index 0000000..791cfb1 --- /dev/null +++ b/libutils/cuda/Stream.h @@ -0,0 +1,85 @@ +/* + 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_STREAM_H +#define FM7b5_CUDA_STREAM_H + +#include +#include + +class Stream +{ +public: + Stream(); + ~Stream(); + operator cudaStream_t(); + + cudaError_t query() const; + cudaError_t synchronize() const; + cudaError_t wait_event(cudaEvent_t event, unsigned int flags) const; + +protected: + cudaStream_t m_stream; +}; + +Stream::Stream() +{ + cudaError_t status; + + status = cudaStreamCreate(&m_stream); + + if (status != cudaSuccess) { + throw std::runtime_error(cudaGetErrorString(status)); + } +} + +Stream::~Stream() +{ + cudaError_t status; + + status = cudaStreamDestroy(m_stream); + + if (status != cudaSuccess) { + throw std::runtime_error(cudaGetErrorString(status)); + } +} + +Stream::operator cudaStream_t() +{ + return m_stream; +} + +cudaError_t +Stream::query() const +{ + return cudaStreamQuery(m_stream); +} + +cudaError_t +Stream::synchronize() const +{ + return cudaStreamSynchronize(m_stream); + +} + +cudaError_t +Stream::wait_event(cudaEvent_t event, unsigned int flags) const +{ + return cudaStreamWaitEvent(m_stream, event, flags); +} + +#endif /* FM7b5_CUDA_STREAM_H */ diff --git a/libutils/cuda/cuda_wrapper.h b/libutils/cuda/cuda_wrapper.h new file mode 100644 index 0000000..409d011 --- /dev/null +++ b/libutils/cuda/cuda_wrapper.h @@ -0,0 +1,28 @@ +/* + 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_CUDA_WRAPPER_H +#define FM7b5_CUDA_CUDA_WRAPPER_H + +namespace FM7b5 { + namespace cuda { +# include "cuda\Event.h" +# include "cuda\Stream.h" + } +} + +#endif /* FM7b5_CUDA_CUDA_WRAPPER_H */ diff --git a/libutils/libutils.vcxproj b/libutils/libutils.vcxproj index 09f2ea2..a132e66 100644 --- a/libutils/libutils.vcxproj +++ b/libutils/libutils.vcxproj @@ -29,6 +29,7 @@ + @@ -71,6 +72,9 @@ + + + @@ -87,5 +91,6 @@ + \ No newline at end of file diff --git a/libutils/libutils.vcxproj.filters b/libutils/libutils.vcxproj.filters index f5687b6..dd35f93 100644 --- a/libutils/libutils.vcxproj.filters +++ b/libutils/libutils.vcxproj.filters @@ -13,6 +13,9 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {89cff485-2418-4e75-bc0c-97230fe9747b} + @@ -37,6 +40,15 @@ ヘッダー ファイル + + ヘッダー ファイル\cuda + + + ヘッダー ファイル\cuda + + + ヘッダー ファイル\cuda + -- 1.7.12.4