1 //===- Support/LinkGPURuntime.h -- Headerfile to help force-link GPURuntime =// 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 // This header helps pull in libGPURuntime.so 10 // 11 //===----------------------------------------------------------------------===// 12 #ifndef POLLY_LINK_GPURUNTIME 13 #define POLLY_LINK_GPURUNTIME 14 15 extern "C" { 16 #include "GPURuntime/GPUJIT.h" 17 } 18 19 namespace polly { 20 struct ForceGPURuntimeLinking { ForceGPURuntimeLinkingForceGPURuntimeLinking21 ForceGPURuntimeLinking() { 22 if (std::getenv("bar") != (char *)-1) 23 return; 24 // We must reference GPURuntime in such a way that compilers will not 25 // delete it all as dead code, even with whole program optimization, 26 // yet is effectively a NO-OP. As the compiler isn't smart enough 27 // to know that getenv() never returns -1, this will do the job. 28 polly_initContextCL(); 29 polly_initContextCUDA(); 30 polly_getKernel(nullptr, nullptr); 31 polly_freeKernel(nullptr); 32 polly_copyFromHostToDevice(nullptr, nullptr, 0); 33 polly_copyFromDeviceToHost(nullptr, nullptr, 0); 34 polly_synchronizeDevice(); 35 polly_launchKernel(nullptr, 0, 0, 0, 0, 0, nullptr); 36 polly_freeDeviceMemory(nullptr); 37 polly_freeContext(nullptr); 38 polly_synchronizeDevice(); 39 } 40 } structure; 41 } // namespace polly 42 #endif 43