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 #pragma omp declare target
15 
16 namespace _OMP {
17 namespace impl {
18 
19 /// AMDGCN Implementation
20 ///
21 ///{
22 #pragma omp begin declare variant match(device = {arch(amdgcn)})
23 
getWTick()24 double getWTick() { return ((double)1E-9); }
25 
getWTime()26 double getWTime() {
27   // The intrinsics for measuring time have undocumented frequency
28   // This will probably need to be found by measurement on a number of
29   // architectures. Until then, return 0, which is very inaccurate as a
30   // timer but resolves the undefined symbol at link time.
31   return 0;
32 }
33 
34 #pragma omp end declare variant
35 
36 /// NVPTX Implementation
37 ///
38 ///{
39 #pragma omp begin declare variant match(                                       \
40     device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any)})
41 
getWTick()42 double getWTick() {
43   // Timer precision is 1ns
44   return ((double)1E-9);
45 }
46 
getWTime()47 double getWTime() {
48   unsigned long long nsecs;
49   asm("mov.u64  %0, %%globaltimer;" : "=l"(nsecs));
50   return (double)nsecs * getWTick();
51 }
52 
53 #pragma omp end declare variant
54 
55 } // namespace impl
56 } // namespace _OMP
57 
58 /// Interfaces
59 ///
60 ///{
61 
62 extern "C" {
__kmpc_cancellationpoint(IdentTy *,int32_t,int32_t)63 int32_t __kmpc_cancellationpoint(IdentTy *, int32_t, int32_t) { return 0; }
64 
__kmpc_cancel(IdentTy *,int32_t,int32_t)65 int32_t __kmpc_cancel(IdentTy *, int32_t, int32_t) { return 0; }
66 
omp_get_wtick(void)67 double omp_get_wtick(void) { return _OMP::impl::getWTick(); }
68 
omp_get_wtime(void)69 double omp_get_wtime(void) { return _OMP::impl::getWTime(); }
70 }
71 
72 ///}
73 #pragma omp end declare target
74