[PATCH] D33198: Header file to help forcibly link GPURuntime
Singapuram Sanjay Srivallabh via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 15 07:37:18 PDT 2017
singam-sanjay created this revision.
singam-sanjay added a project: Polly.
Herald added a subscriber: mgorny.
LinkGPURuntime.h defines the function ForceGPURuntimeLinking which creates an artificial dependency to functions defined in GPUJIT.c. A call to this function ensures that these functions are a part of the compiled object/library files calling it.
Repository:
rL LLVM
https://reviews.llvm.org/D33198
Files:
CMakeLists.txt
include/polly/Support/LinkGPURuntime.h
Index: include/polly/Support/LinkGPURuntime.h
===================================================================
--- /dev/null
+++ include/polly/Support/LinkGPURuntime.h
@@ -0,0 +1,45 @@
+//===- ??FOLDER??/LinkGPURuntime.h -- Headerfile to help force-link GPURuntime --------------------===//
+//////
+////// The LLVM Compiler Infrastructure
+//////
+////// This file is distributed under the University of Illinois Open Source
+////// License. See LICENSE.TXT for details.
+//////
+//////===----------------------------------------------------------------------===//
+//////
+////// This header helps pull in libGPURuntime.so
+//////
+//////===----------------------------------------------------------------------===//
+//////
+//
+#ifndef POLLY_LINK_GPURUNTIME
+#define POLLY_LINK_GPURUNTIME
+
+extern "C"
+{
+ #include "GPURuntime/GPUJIT.c"
+}
+
+namespace polly {
+ void ForceGPURuntimeLinking()
+ {
+ if (std::getenv("bar") != (char*) -1)
+ return;
+ // We must reference GPURuntime in such a way that compilers will not
+ // delete it all as dead code, even with whole program optimization,
+ // yet is effectively a NO-OP. As the compiler isn't smart enough
+ // to know that getenv() never returns -1, this will do the job.
+ polly_initContextCL();
+ polly_initContextCUDA();
+ polly_getKernel(nullptr, nullptr);
+ polly_freeKernel((PollyGPUFunction*)nullptr);
+ polly_copyFromHostToDevice(nullptr, (PollyGPUDevicePtr*)nullptr, 0);
+ polly_copyFromDeviceToHost((PollyGPUDevicePtr*)nullptr, nullptr, 0);
+ polly_synchronizeDevice();
+ polly_launchKernel((PollyGPUFunction*)nullptr, 0, 0, 0, 0, 0, (void**)nullptr);
+ polly_freeDeviceMemory((PollyGPUDevicePtr*)nullptr);
+ polly_freeContext((PollyGPUContext*)nullptr);
+ polly_synchronizeDevice();
+ }
+}
+#endif
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -206,6 +206,7 @@
${JSONCPP_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
${CMAKE_CURRENT_SOURCE_DIR}/lib/External
+ ${CMAKE_CURRENT_SOURCE_DIR}/tools
${CMAKE_CURRENT_BINARY_DIR}/include
)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33198.99004.patch
Type: text/x-patch
Size: 2206 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170515/3c601e03/attachment.bin>
More information about the llvm-commits
mailing list