• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 // CUDA userspace driver library wrapper functionality.
17 
18 #ifndef TENSORFLOW_STREAM_EXECUTOR_CUDA_CUDA_DRIVER_H_
19 #define TENSORFLOW_STREAM_EXECUTOR_CUDA_CUDA_DRIVER_H_
20 
21 #include "tensorflow/stream_executor/gpu/gpu_driver.h"
22 
23 namespace stream_executor {
24 namespace gpu {
25 // CUDAContext wraps a cuda CUcontext handle, and includes a unique id. The
26 // unique id is positive, and ids are not repeated within the process.
27 class GpuContext {
28  public:
GpuContext(CUcontext context,int64 id)29   GpuContext(CUcontext context, int64 id) : context_(context), id_(id) {}
30 
context()31   CUcontext context() const { return context_; }
id()32   int64 id() const { return id_; }
33 
34   // Disallow copying and moving.
35   GpuContext(GpuContext&&) = delete;
36   GpuContext(const GpuContext&) = delete;
37   GpuContext& operator=(GpuContext&&) = delete;
38   GpuContext& operator=(const GpuContext&) = delete;
39 
40  private:
41   CUcontext const context_;
42   const int64 id_;
43 };
44 
45 }  // namespace gpu
46 
47 namespace cuda {
48 
49 using MemorySpace = gpu::MemorySpace;
50 
51 using CUDADriver = gpu::GpuDriver;
52 
53 using ScopedActivateContext = gpu::ScopedActivateContext;
54 
55 using CudaContext = gpu::GpuContext;
56 
57 // Returns the current context set in CUDA. This is done by calling the cuda
58 // driver (e.g., this value is not our cached view of the current context).
59 CUcontext CurrentContextOrDie();
60 
61 }  // namespace cuda
62 }  // namespace stream_executor
63 
64 #endif  // TENSORFLOW_STREAM_EXECUTOR_CUDA_CUDA_DRIVER_H_
65