diff options
author | Jason Henline <jhen@google.com> | 2016-09-02 17:22:42 +0000 |
---|---|---|
committer | Jason Henline <jhen@google.com> | 2016-09-02 17:22:42 +0000 |
commit | 31b88cb030fab7b35720c78798e7efff1596187a (patch) | |
tree | 911433284942c62e6fcfb824353b13a7a61b0462 /parallel-libs/streamexecutor/lib | |
parent | 26c43c879c3540aba03a2d67d3848a6b66b4b90a (diff) | |
download | bcm5719-llvm-31b88cb030fab7b35720c78798e7efff1596187a.tar.gz bcm5719-llvm-31b88cb030fab7b35720c78798e7efff1596187a.zip |
[SE] GlobalDeviceMemory owns its handle
Summary:
Final step in getting GlobalDeviceMemory to own its handle.
* Make GlobalDeviceMemory movable, but no longer copyable.
* Make Device::freeDeviceMemory function private and make
GlobalDeviceMemoryBase a friend of Device so GlobalDeviceMemoryBase
can free its memory in its destructor.
* Make GlobalDeviceMemory constructor private and make Device a friend
so it can construct GlobalDeviceMemory.
* Remove SharedDeviceMemoryBase class because it is never used.
* Remove explicit memory freeing from example code.
This change just consumes any errors generated during device memory freeing.
The real error handling will be added in a future patch.
Reviewers: jlebar
Subscribers: jprice, parallel_libs-commits
Differential Revision: https://reviews.llvm.org/D24195
llvm-svn: 280509
Diffstat (limited to 'parallel-libs/streamexecutor/lib')
-rw-r--r-- | parallel-libs/streamexecutor/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | parallel-libs/streamexecutor/lib/DeviceMemory.cpp | 28 | ||||
-rw-r--r-- | parallel-libs/streamexecutor/lib/unittests/DeviceTest.cpp | 1 |
3 files changed, 29 insertions, 1 deletions
diff --git a/parallel-libs/streamexecutor/lib/CMakeLists.txt b/parallel-libs/streamexecutor/lib/CMakeLists.txt index aa16f508661..79ae5c748b0 100644 --- a/parallel-libs/streamexecutor/lib/CMakeLists.txt +++ b/parallel-libs/streamexecutor/lib/CMakeLists.txt @@ -7,6 +7,7 @@ add_library( streamexecutor $<TARGET_OBJECTS:utils> Device.cpp + DeviceMemory.cpp Kernel.cpp KernelSpec.cpp PackedKernelArgumentArray.cpp diff --git a/parallel-libs/streamexecutor/lib/DeviceMemory.cpp b/parallel-libs/streamexecutor/lib/DeviceMemory.cpp new file mode 100644 index 00000000000..62b702b8acf --- /dev/null +++ b/parallel-libs/streamexecutor/lib/DeviceMemory.cpp @@ -0,0 +1,28 @@ +//===-- DeviceMemory.cpp - DeviceMemory implementation --------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// Implementation of DeviceMemory class internals. +/// +//===----------------------------------------------------------------------===// + +#include "streamexecutor/DeviceMemory.h" + +#include "streamexecutor/Device.h" + +namespace streamexecutor { + +GlobalDeviceMemoryBase::~GlobalDeviceMemoryBase() { + if (Handle) { + // TODO(jhen): How to handle errors here. + consumeError(TheDevice->freeDeviceMemory(*this)); + } +} + +} // namespace streamexecutor diff --git a/parallel-libs/streamexecutor/lib/unittests/DeviceTest.cpp b/parallel-libs/streamexecutor/lib/unittests/DeviceTest.cpp index 6e55aa51207..593f1d1cd37 100644 --- a/parallel-libs/streamexecutor/lib/unittests/DeviceTest.cpp +++ b/parallel-libs/streamexecutor/lib/unittests/DeviceTest.cpp @@ -78,7 +78,6 @@ TEST_F(DeviceTest, AllocateAndFreeDeviceMemory) { se::Expected<se::GlobalDeviceMemory<int>> MaybeMemory = Device.allocateDeviceMemory<int>(10); EXPECT_TRUE(static_cast<bool>(MaybeMemory)); - EXPECT_NO_ERROR(Device.freeDeviceMemory(*MaybeMemory)); } TEST_F(DeviceTest, AllocateAndFreeHostMemory) { |