Viskores  1.0
ScopedCudaStackSize.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_cont_cuda_internal_ScopedCudaStackSize_h
19 #define viskores_cont_cuda_internal_ScopedCudaStackSize_h
20 
21 namespace viskores
22 {
23 namespace cont
24 {
25 namespace cuda
26 {
27 namespace internal
28 {
29 
32 struct ScopedCudaStackSize
33 {
34  ScopedCudaStackSize(std::size_t newStackSize)
35  {
36  cudaDeviceGetLimit(&this->OldStackSize, cudaLimitStackSize);
39  "Temporarily changing Cuda stack size from "
40  << viskores::cont::GetHumanReadableSize(static_cast<viskores::UInt64>(this->OldStackSize))
41  << " to "
42  << viskores::cont::GetHumanReadableSize(static_cast<viskores::UInt64>(newStackSize)));
43  cudaDeviceSetLimit(cudaLimitStackSize, newStackSize);
44  }
45 
46  ~ScopedCudaStackSize()
47  {
49  "Restoring Cuda stack size to " << viskores::cont::GetHumanReadableSize(
50  static_cast<viskores::UInt64>(this->OldStackSize)));
51  cudaDeviceSetLimit(cudaLimitStackSize, this->OldStackSize);
52  }
53 
54  // Disable copy
55  ScopedCudaStackSize(const ScopedCudaStackSize&) = delete;
56  ScopedCudaStackSize& operator=(const ScopedCudaStackSize&) = delete;
57 
58 private:
59  std::size_t OldStackSize;
60 };
61 }
62 }
63 }
64 } // viskores::cont::cuda::internal
65 
66 #endif // viskores_cont_cuda_internal_ScopedCudaStackSize_h
viskores::cont::GetHumanReadableSize
std::string GetHumanReadableSize(viskores::UInt64 bytes, int prec=2)
Convert a size in bytes to a human readable string (such as "64 bytes", "1.44 MiB",...
viskores::cont::LogLevel::Info
@ Info
Information messages (detected hardware, etc) and temporary debugging output.
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::UInt64
unsigned long long UInt64
Base type to use for 64-bit signed integer numbers.
Definition: Types.h:215
VISKORES_LOG_S
#define VISKORES_LOG_S(level,...)
Writes a message using stream syntax to the indicated log level.
Definition: Logging.h:216