• 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 #ifndef TENSORFLOW_CORE_PLATFORM_DEFAULT_CUPTI_WRAPPER_H_
17 #define TENSORFLOW_CORE_PLATFORM_DEFAULT_CUPTI_WRAPPER_H_
18 
19 #if GOOGLE_CUDA
20 
21 #include <stddef.h>
22 #include <stdint.h>
23 #if defined(WIN32)
24 #include "extras/CUPTI/include/cupti.h"
25 #else
26 #include "cupti.h"
27 #endif
28 namespace perftools {
29 namespace gputools {
30 namespace profiler {
31 
32 // Wraps the CUPTI API so that we can dynamically load the library.
33 class CuptiWrapper {
34  public:
CuptiWrapper()35   CuptiWrapper() {}
36 
37   // CUPTI activity API
38   CUptiResult ActivityDisable(CUpti_ActivityKind kind);
39 
40   CUptiResult ActivityEnable(CUpti_ActivityKind kind);
41 
42   CUptiResult ActivityFlushAll(uint32_t flag);
43 
44   CUptiResult ActivityGetNextRecord(uint8_t* buffer,
45                                     size_t valid_buffer_size_bytes,
46                                     CUpti_Activity** record);
47 
48   CUptiResult ActivityGetNumDroppedRecords(CUcontext context,
49                                            uint32_t stream_id, size_t* dropped);
50 
51   CUptiResult ActivityRegisterCallbacks(
52       CUpti_BuffersCallbackRequestFunc func_buffer_requested,
53       CUpti_BuffersCallbackCompleteFunc func_buffer_completed);
54 
55   CUptiResult GetDeviceId(CUcontext context, uint32_t* deviceId);
56 
57   CUptiResult GetTimestamp(uint64_t* timestamp);
58 
59   // CUPTI callback API
60   CUptiResult EnableCallback(uint32_t enable, CUpti_SubscriberHandle subscriber,
61                              CUpti_CallbackDomain domain,
62                              CUpti_CallbackId cbid);
63 
64   CUptiResult EnableDomain(uint32_t enable, CUpti_SubscriberHandle subscriber,
65                            CUpti_CallbackDomain domain);
66 
67   CUptiResult Subscribe(CUpti_SubscriberHandle* subscriber,
68                         CUpti_CallbackFunc callback, void* userdata);
69 
70   CUptiResult Unsubscribe(CUpti_SubscriberHandle subscriber);
71 
72   CUptiResult GetResultString(CUptiResult result, const char** str);
73 };
74 
75 }  // namespace profiler
76 }  // namespace gputools
77 }  // namespace perftools
78 
79 #endif  // GOOGLE_CUDA
80 
81 #endif  // TENSORFLOW_CORE_PLATFORM_DEFAULT_CUPTI_WRAPPER_H_
82