1 //===--------- Misc.cpp - OpenMP device misc interfaces ----------- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 //
10 //===----------------------------------------------------------------------===//
11 
12 #include "Types.h"
13 
14 #include "Debug.h"
15 
16 #pragma omp begin declare target device_type(nohost)
17 
18 namespace _OMP {
19 namespace impl {
20 
21 double getWTick();
22 
23 double getWTime();
24 
25 /// AMDGCN Implementation
26 ///
27 ///{
28 #pragma omp begin declare variant match(device = {arch(amdgcn)})
29 
30 double getWTick() { return ((double)1E-9); }
31 
32 double getWTime() {
33   // The intrinsics for measuring time have undocumented frequency
34   // This will probably need to be found by measurement on a number of
35   // architectures. Until then, return 0, which is very inaccurate as a
36   // timer but resolves the undefined symbol at link time.
37   return 0;
38 }
39 
40 #pragma omp end declare variant
41 
42 /// NVPTX Implementation
43 ///
44 ///{
45 #pragma omp begin declare variant match(                                       \
46     device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any)})
47 
48 double getWTick() {
49   // Timer precision is 1ns
50   return ((double)1E-9);
51 }
52 
53 double getWTime() {
54   unsigned long long nsecs;
55   asm("mov.u64  %0, %%globaltimer;" : "=l"(nsecs));
56   return (double)nsecs * getWTick();
57 }
58 
59 #pragma omp end declare variant
60 
61 } // namespace impl
62 } // namespace _OMP
63 
64 /// Interfaces
65 ///
66 ///{
67 
68 extern "C" {
69 int32_t __kmpc_cancellationpoint(IdentTy *, int32_t, int32_t) {
70   FunctionTracingRAII();
71   return 0;
72 }
73 
74 int32_t __kmpc_cancel(IdentTy *, int32_t, int32_t) {
75   FunctionTracingRAII();
76   return 0;
77 }
78 
79 double omp_get_wtick(void) { return _OMP::impl::getWTick(); }
80 
81 double omp_get_wtime(void) { return _OMP::impl::getWTime(); }
82 }
83 
84 ///}
85 #pragma omp end declare target
86