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