elvin-n commented on code in PR #13362:
URL: https://github.com/apache/tvm/pull/13362#discussion_r1021987579
##########
cmake/modules/OpenCL.cmake:
##########
@@ -49,12 +49,17 @@ else()
endif(USE_AOCL)
if(USE_OPENCL)
- if (NOT OpenCL_FOUND)
- find_package(OpenCL REQUIRED)
- endif()
- message(STATUS "Build with OpenCL support")
tvm_file_glob(GLOB RUNTIME_OPENCL_SRCS src/runtime/opencl/*.cc)
- list(APPEND TVM_RUNTIME_LINKER_LIBS ${OpenCL_LIBRARIES})
+ if (OpenCL_FOUND)
+ message(STATUS "Build with OpenCL support")
Review Comment:
What are the cases when we find opencl and link vs it? Do we assume this
wrapper not cover all cases and we will need to link vs original opencl?
##########
src/runtime/opencl/opencl_wrapper/opencl_wrapper.cc:
##########
@@ -0,0 +1,551 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file opencl_wrapper.cc
+ */
+
+#define CL_TARGET_OPENCL_VERSION 120
+#include <CL/cl.h>
+#include <CL/cl_gl.h>
+
+#define DMLC_USE_LOGGING_LIBRARY <tvm/runtime/logging.h>
+#include <dlfcn.h>
+#include <tvm/runtime/logging.h>
+
+#include <vector>
+
+namespace {
+#if defined(__APPLE__) || defined(__MACOSX)
+static const std::vector<const char*> default_so_paths = {
+ "libOpenCL.so", "/System/Library/Frameworks/OpenCL.framework/OpenCL"};
+#elif defined(__ANDROID__)
+static const std::vector<const char*> default_so_paths = {
+ "libOpenCL.so",
+ "/system/lib64/libOpenCL.so",
+ "/system/vendor/lib64/libOpenCL.so",
+ "/system/vendor/lib64/egl/libGLES_mali.so",
+ "/system/vendor/lib64/libPVROCL.so",
+ "/data/data/org.pocl.libs/files/lib64/libpocl.so",
+ "/system/lib/libOpenCL.so",
+ "/system/vendor/lib/libOpenCL.so",
+ "/system/vendor/lib/egl/libGLES_mali.so",
+ "/system/vendor/lib/libPVROCL.so",
+ "/data/data/org.pocl.libs/files/lib/libpocl.so"};
+#elif defined(_WIN32)
+static const std::vector<const char*> default_so_paths = {"OpenCL.dll"};
+#elif defined(__linux__)
+static const std::vector<const char*> default_so_paths = {"libOpenCL.so",
+
"/usr/lib/libOpenCL.so",
+
"/usr/local/lib/libOpenCL.so",
+
"/usr/local/lib/libpocl.so",
+
"/usr/lib64/libOpenCL.so",
+
"/usr/lib32/libOpenCL.so"};
+#endif
+
+class LibOpenCLWrapper {
+ public:
+ static LibOpenCLWrapper& getInstance() {
+ static LibOpenCLWrapper instance;
+ return instance;
+ }
+ LibOpenCLWrapper(const LibOpenCLWrapper&) = delete;
+ LibOpenCLWrapper& operator=(const LibOpenCLWrapper&) = delete;
+ void* getOpenCLFunction(const char* funcName) {
+ if (m_libHandler == nullptr) openLibOpenCL();
+ return dlsym(m_libHandler, funcName);
+ }
+
+ private:
+ LibOpenCLWrapper() {}
+ ~LibOpenCLWrapper() {
+ if (m_libHandler) dlclose(m_libHandler);
+ }
+ void openLibOpenCL() {
+ for (const auto it : default_so_paths) {
+ m_libHandler = dlopen(it, RTLD_LAZY);
Review Comment:
this must not work on Windows. Need to branch and use
LoadLibrary/GetProcAddress/FreeLibrary
##########
apps/cpp_rpc/README.md:
##########
@@ -37,7 +37,15 @@ This folder contains a simple recipe to make RPC server in
c++.
# Path to the desired C++ cross compiler
set(CMAKE_CXX_COMPILER /path/to/cross/compiler/executable)
```
-- If linking against a custom device OpenCL library is needed, in the config
specify the path to the OpenCL SDK containing the include/CL headers and lib/
or lib64/libOpenCL.so:
+- If you need to build cpp_rpc with OpenCL support, specify variable
`USE_OPENCL` in the config:
+ ```
+ set(USE_OPENCL ON)
+ ```
+ In this case [OpenCL-wrapper](../../src/runtime/opencl/opencl_wrapper) or
OpenCL installed to your system will be used.
Review Comment:
> or OpenCL installed
did you mean OpenCL SDK?
Do we consider OpenCL SDK flow at all?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]