1 /* Copyright 2019 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 #include "tensorflow/core/profiler/internal/cpu/annotation_stack.h"
17 
18 #include <atomic>
19 
20 #include "tensorflow/core/platform/types.h"
21 
22 namespace tensorflow {
23 namespace profiler {
24 namespace internal {
25 
26 std::atomic<int> g_annotation_enabled(0);
27 
28 // g_annotation_enabled implementation must be lock-free for faster execution of
29 // the ScopedAnnotation API. This can be commented (if compilation is failing)
30 // but execution might be slow (even when tracing is disabled).
31 static_assert(ATOMIC_INT_LOCK_FREE == 2, "Assumed atomic<int> was lock free");
32 
33 }  // namespace internal
34 
ThreadAnnotationStack()35 /*static*/ string* AnnotationStack::ThreadAnnotationStack() {
36   static thread_local string annotation_stack;
37   return &annotation_stack;
38 }
39 
40 }  // namespace profiler
41 }  // namespace tensorflow
42