cudaEvent_tとcudaStream_tのラッパを追加
authordev <dev@fmaj7b5.info>
Sat, 29 Jun 2013 15:58:25 +0000 (00:58 +0900)
committerdev <dev@fmaj7b5.info>
Mon, 1 Jul 2013 09:47:24 +0000 (18:47 +0900)
libutils/cuda/Event.h [new file with mode: 0644]
libutils/cuda/Stream.h [new file with mode: 0644]
libutils/cuda/cuda_wrapper.h [new file with mode: 0644]
libutils/libutils.vcxproj
libutils/libutils.vcxproj.filters

diff --git a/libutils/cuda/Event.h b/libutils/cuda/Event.h
new file mode 100644 (file)
index 0000000..a1b2b14
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef FM7b5_CUDA_EVENT_H
+#define FM7b5_CUDA_EVENT_H
+
+#include <stdexcept>
+#include <cuda_runtime.h>
+
+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 (file)
index 0000000..791cfb1
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef FM7b5_CUDA_STREAM_H
+#define FM7b5_CUDA_STREAM_H
+
+#include <stdexcept>
+#include <cuda_runtime.h>
+
+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 (file)
index 0000000..409d011
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+*/
+
+#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 */
index 09f2ea2..a132e66 100644 (file)
@@ -29,6 +29,7 @@
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
+    <Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 4.2.props" />
   </ImportGroup>
   <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
@@ -71,6 +72,9 @@
     <None Include="ReadMe.txt" />
   </ItemGroup>
   <ItemGroup>
+    <ClInclude Include="cuda\cuda_wrapper.h" />
+    <ClInclude Include="cuda\Event.h" />
+    <ClInclude Include="cuda\Stream.h" />
     <ClInclude Include="DeviceMemory.cuh" />
     <ClInclude Include="Image.h" />
     <ClInclude Include="ImageIO.h" />
@@ -87,5 +91,6 @@
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
+    <Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 4.2.targets" />
   </ImportGroup>
 </Project>
\ No newline at end of file
index f5687b6..dd35f93 100644 (file)
@@ -13,6 +13,9 @@
       <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
       <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
     </Filter>
+    <Filter Include="ヘッダー ファイル\cuda">
+      <UniqueIdentifier>{89cff485-2418-4e75-bc0c-97230fe9747b}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <None Include="ReadMe.txt" />
     <ClInclude Include="MDView.cuh">
       <Filter>ヘッダー ファイル</Filter>
     </ClInclude>
+    <ClInclude Include="cuda\cuda_wrapper.h">
+      <Filter>ヘッダー ファイル\cuda</Filter>
+    </ClInclude>
+    <ClInclude Include="cuda\Event.h">
+      <Filter>ヘッダー ファイル\cuda</Filter>
+    </ClInclude>
+    <ClInclude Include="cuda\Stream.h">
+      <Filter>ヘッダー ファイル\cuda</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="stdafx.cpp">