From 9263dd5481ce606107ac2efa0d293e550858335a Mon Sep 17 00:00:00 2001 From: dengliqiang Date: Thu, 12 Sep 2019 18:26:31 +0800 Subject: [PATCH 1/7] Load intel opencl driver by default and fix compiling issue in Android 1, in Android, only one OpenCL driver is loaded, then it is unnecessary to load driver from icd file 2, fix compiling issue in Android to not include file "icd_cmake_config.h" Signed-off-by: dengliqiang --- loader/linux/icd_linux.c | 3 +++ loader/linux/icd_linux_envvars.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/loader/linux/icd_linux.c b/loader/linux/icd_linux.c index f6ae790..c7acc42 100644 --- a/loader/linux/icd_linux.c +++ b/loader/linux/icd_linux.c @@ -38,6 +38,7 @@ static pthread_once_t initialized = PTHREAD_ONCE_INIT; // go through the list of vendors in the two configuration files void khrIcdOsVendorsEnumerate(void) { +#ifndef __ANDROID__ DIR *dir = NULL; struct dirent *dirEntry = NULL; char* vendorPath = ICD_VENDOR_PATH; @@ -141,6 +142,8 @@ void khrIcdOsVendorsEnumerate(void) { khrIcd_free_getenv(envPath); } +#endif + khrIcdVendorAdd("/vendor/lib64/libigdrcl.so"); } // go through the list of vendors only once diff --git a/loader/linux/icd_linux_envvars.c b/loader/linux/icd_linux_envvars.c index 4af5a08..b71432e 100644 --- a/loader/linux/icd_linux_envvars.c +++ b/loader/linux/icd_linux_envvars.c @@ -21,7 +21,9 @@ #define _GNU_SOURCE #endif +#ifndef __ANDROID__ #include "icd_cmake_config.h" +#endif #include From df3a17e23e0ab09ee09a5a440b9e72e27a3af687 Mon Sep 17 00:00:00 2001 From: dengliqiang Date: Thu, 12 Sep 2019 20:23:39 +0800 Subject: [PATCH 2/7] Add the templates and script for generating bp files Signed-off-by: dengliqiang --- bp/defaults.tpl | 55 +++++ bp/icd-loader.tpl | 82 ++++++++ scripts/androidbpgenerator.py | 313 +++++++++++++++++++++++++++++ scripts/cleanicdloadergenerator.py | 49 +++++ scripts/icdloadergenerator.py | 77 +++++++ 5 files changed, 576 insertions(+) create mode 100755 bp/defaults.tpl create mode 100755 bp/icd-loader.tpl create mode 100755 scripts/androidbpgenerator.py create mode 100755 scripts/cleanicdloadergenerator.py create mode 100755 scripts/icdloadergenerator.py diff --git a/bp/defaults.tpl b/bp/defaults.tpl new file mode 100755 index 0000000..9730967 --- /dev/null +++ b/bp/defaults.tpl @@ -0,0 +1,55 @@ +# Copyright(c) 2019 Intel Corporation +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files(the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and / or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +cc_defaults { + name: "@name", + + vendor_available: true, + + cflags: [ +@cflags + ], + + cppflags: [ +@cppflags + ], + + clang_cflags: [ +@clang_cflags + ], + + include_dirs: [ +@include_dirs + ], + + shared_libs: [ +@shared_libs + ], + + static_libs: [ +@static_libs + ], + +} + + +build = [ +@build +] \ No newline at end of file diff --git a/bp/icd-loader.tpl b/bp/icd-loader.tpl new file mode 100755 index 0000000..6b537e1 --- /dev/null +++ b/bp/icd-loader.tpl @@ -0,0 +1,82 @@ +# Copyright(c) 2019 Intel Corporation +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files(the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and / or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +# The file-tree of OpenCL-ICD-Loader +# OpenCL-ICD-Loader (cmake -DCMAKE_BUILD_TYPE=Release OpenCL-ICD-Loader) +# | +# +---- libOpenCL.so.1.2 -> Tools/Android/build/icd-loader/CMakeFiles/OpenCL.dir +# | +# +---- test +# | +# +---- log +# | | +# | +---- libIcdLog.so -> Tools/Android/build/icd-loader/test/platform/CMakeFiles/IcdLog.dir +# | +# +---- loader_test +# | | +# | +---- icd_loader_test -> Tools/Android/build/icd-loader/test/loader_test/CMakeFiles/icd_loader_test.dir +# | | +# | => libOpenCL.so.1.2, libIcdLog.so +# | +# +---- driver_stub +# | +# +---- libOpenCLDriverStub.so -> Tools/Android/build/icd-loader/test/driver_stub/CMakeFiles/OpenCLDriverStub.dir +# | +# => libIcdLog.so +# +# About the detailed of soong-build-tools(cc package), please refer to: +# https://ci.android.com/builds/submitted/5357401/linux/latest/view/soong_build.html +# +# +# library_static, library_shared, binary +cc_@module { + name: "@name", + + vendor_available: true, + + defaults: [ +@defaults + ], + + srcs: [ +@srcs + ], + + cflags: [ +@cflags + ], + + cppflags: [ +@cppflags + ], + + local_include_dirs: [ +@local_include_dirs + ], + + shared_libs: [ +@shared_libs + ], + + static_libs: [ +@static_libs + ], + +} \ No newline at end of file diff --git a/scripts/androidbpgenerator.py b/scripts/androidbpgenerator.py new file mode 100755 index 0000000..2ff92b8 --- /dev/null +++ b/scripts/androidbpgenerator.py @@ -0,0 +1,313 @@ +#! /usr/bin/env python3 +""" +* Copyright (c) 2019, Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +""" + +import os +import os.path as path +import re + + +INDENT = " " +BUILD_DIR = "__build__" +TEMPLATE_DIR = "bp" +NOVERBOSE = " > /dev/null 2>&1;" + + +def remove(f): + cmd = "rm -f " + f + NOVERBOSE + os.system(cmd) + + +class CCDefaults: + # constructor + def __init__(self, proj, defname, cflags = [], cppflags = [], clang_cflags = [], + include_dirs = [], shared_libs = [], static_libs = [], bpfiles = []): + self.templ = path.join(proj, TEMPLATE_DIR) + self.proj = proj + self.default_name = defname + self.c_flag = cflags + self.cpp_flag = cppflags + self.clang_cflag = clang_cflags + self.include_dir = include_dirs + self.shared_lib = shared_libs + self.static_lib = static_libs + self.bp_file = bpfiles + + def getBpFilePath(self): + return path.join(self.proj, "Android.bp") + + #major function + def generate(self): + if path.exists(self.proj) == False: + raise Exception(self.proj + " not existed") + # read template + with open(path.join(self.templ, "defaults.tpl")) as f: + tpl = f.read() + # remove all comment + tpl = re.sub("#.*\n", "", tpl).strip() + # replacement + tpl = tpl.replace("@name", self.default_name) + tpl = tpl.replace("@cflags", self.convertList2Str(self.c_flag)) + tpl = tpl.replace("@cppflags", self.convertList2Str(self.cpp_flag)) + tpl = tpl.replace("@clang_cflags", self.convertList2Str(self.clang_cflag)) + tpl = tpl.replace("@include_dirs", self.convertList2Str(self.include_dir)) + tpl = tpl.replace("@shared_libs", self.convertList2Str(self.shared_lib)) + tpl = tpl.replace("@static_libs", self.convertList2Str(self.static_lib)) + tpl = tpl.replace("@build", self.convertList2Str(self.bp_file, indent_num = 1)) + + return tpl + + def convertList2Str(self, itemlist, indent_num = 2): + str = "" + + for i, t in enumerate(itemlist): + if 0 == len(t): + continue + str += INDENT * indent_num + "\"" + t + "\",\n" + + return INDENT * indent_num + "".join(str).strip() + + +class ModuleInfo: + # constructor + def __init__(self, modulename, bpfilename, cmakedir, moduletype, defaults, + middledir = "", addsrc = [], addflags = [], addstatic = [], addshared = [], + updateflags = {}, updatestatic = {}, updateshared = {}): + self.Module_Name = modulename # name of module + self.Bp_File_Name = bpfilename # BP file name + self.Mid_Dir = middledir # some middle directory + self.Build_Make = middledir + cmakedir + "build.make" # building file in directory generated by cmake + self.Flags_Make = middledir + cmakedir + "flags.make" # flag-file in directory generated by cmake + self.Module_Type = moduletype # support: cc_library_shared, cc_library_static + self.Defaults = INDENT * 2 + "\"" + defaults + "\"," + self.Add_Src = addsrc # some additional source files + self.Add_Flags = addflags # some additional cflags/cppflags + self.Add_Static = addstatic # some additional static library + self.Add_Shared = addshared # some additional shared library + self.Update_Flags = updateflags # update some cflags/cppflags + self.Update_Static = updatestatic # update the dependent static libraries + self.Update_Shared = updateshared # update the dependent static libraries + + +class Generator: + # constructor + def __init__(self, src, root): + # where is the major source file, and the directory to where *.bp should be put + self.src = src + # where to put build file and template + self.build = path.join(root, BUILD_DIR) + """where to put the template""" + self.templ = path.join(src, TEMPLATE_DIR) + # all submodule's info + self.allmoduleinfo = {} + # + # self.allmoduledefaults = CCDefaults(...) + + #major function + def generate(self, to_cmake = True, to_make = False): + if path.exists(self.src) == False: + raise Exception(self.src + " not existed") + + if to_cmake: + self.generateMakefile(make = to_make) + + self.adjustFiles() + + allBPs = {} + # sub-module" .bp + for k in self.allmoduleinfo.keys(): + # the path of Android.bp + bp = path.normpath(path.join(self.src, self.allmoduleinfo[k].Bp_File_Name)) + # read template + with open(self.getTemplatePath()) as f: + tpl = f.read() + # remove all comment + tpl = re.sub("#.*\n", "", tpl).strip() + # an Android.bp is related to some module + if bp in allBPs.keys(): + allBPs[bp] += "\n\n" + self.replaceTemplate(k, tpl) + else: + allBPs[bp] = self.replaceTemplate(k, tpl) + # Android.bp + allBPs[self.allmoduledefaults.getBpFilePath()] = self.allmoduledefaults.generate() + + for bp in allBPs.keys(): + # remove old Android.bp + remove(bp) + # create new Android.bp + with open(bp, "w") as f: + f.write(allBPs[bp]) + print(bp + " has been generated.") + + #virtuall functions + def getTemplate(self): + raise Exception("pure virtul function") + + def replaceTemplate(self, mode, tpl): + tpl = tpl.replace("@module", self.allmoduleinfo[mode].Module_Type) + tpl = tpl.replace("@name", self.allmoduleinfo[mode].Module_Name) + tpl = tpl.replace("@defaults", self.allmoduleinfo[mode].Defaults) + tpl = tpl.replace("@srcs", self.getSources(mode)) + tpl = tpl.replace("@cflags", self.adjustFlags(mode, INDENT * 2 + "".join(self.getDefines(mode, "C_FLAGS") + self.getDefines(mode, "C_DEFINES")).strip(), is_add = False)) + tpl = tpl.replace("@cppflags", self.adjustFlags(mode, INDENT * 2 + "".join(self.getDefines(mode, "CXX_FLAGS") + self.getDefines(mode, "CXX_DEFINES")).strip())) + tpl = tpl.replace("@local_include_dirs", INDENT * 2 + "".join(self.getIncludes(mode, "C_INCLUDES") + "\n" + self.getIncludes(mode, "CXX_INCLUDES")).strip()) + tpl = tpl.replace("@shared_libs", INDENT * 2 + "".join(self.adjustLibrary(mode, self.getLibrary(mode, ".*?\\.so[.\d]*\\n", "\\.so)[.\d]*\\n", "\\.so[.\d]*"), False).strip())) + tpl = tpl.replace("@static_libs", INDENT * 2 + "".join(self.adjustLibrary(mode, self.getLibrary(mode, ".*?\\.a\\n", "\\.a)\\n", "\\.a")).strip())) + + return tpl + + def getName(self): + return self.getTemplate().split(".")[0] + + def getTemplatePath(self): + return path.join(self.templ, self.getTemplate()) + + def getBuildDir(self): + return path.join(self.build, self.getName()) + + def adjustSources(self, mode, all_sources): + return all_sources + + def adjustIncludes(self, mode, all_includes): + return all_includes + + def adjustFlags(self, mode, all_flags, is_add = True): + return all_flags + + def adjustLibrary(self, mode, all_libs, is_static = True): + return all_libs + + def adjustFiles(self): + return + + def getCmakeCmd(self): + return "cmake -DCMAKE_BUILD_TYPE=Release " + self.src + + def generateMakefile(self, debug=False, make=False): + #windows can help us debug the script and we do not want generate makefile on widnows + if os.name == "nt": + return + + verbose = ";" if debug else NOVERBOSE + builddir = self.getBuildDir() + # make quickly, but can't clear old makefile + cmd = "rm " + path.join(builddir, "CMakeCache.txt") + verbose + # clear old makefile, but need to cost some time + #cmd = "rm -rf " + builddir + verbose + cmd += "mkdir -p " + builddir + verbose + cmd += "cd " + builddir + " && " + self.getCmakeCmd() + verbose + # need to make this project + if make: + print("It is making: " + self.src) + cmd += "make -j$(nproc)" + + os.system(cmd) + + def getIncludes(self, mode, title): + includestext = self.getDefines(mode, title) + if (0 == len(includestext)): + return "" + + lines = includestext.split("\n") + includesfile = [] + + for l in lines: + if 0 == len(l): + continue + #normpath will make sure we did not refer outside. + p = path.normpath(l) + j = p.find(self.src) + # + if 0 <= j: + # check this path of include is existed, or not. + k = p[j:].find('"') + if (0 <= k) and (True == path.isdir(p[j : (j + k)])): + includesfile.append(p[j:].replace(self.src, INDENT * 2 + "\"")) + + return "\n".join(includesfile) if includesfile else "" + + def getDefines(self, mode, title): + if not mode in self.allmoduleinfo.keys(): + raise Exception("Invalid index of module info") + + flagsfile = path.join(self.getBuildDir(), self.allmoduleinfo[mode].Flags_Make) + with open(flagsfile) as f: + text = f.read() + + lines = re.findall(title + " =.*\n", text) + if (0 == len(lines)): + return "" + + all_defines = "" + + for i, l in enumerate(lines): + # 'strip' to remove the beginning and ending space + l = l.replace(title + " = ", "").strip() + if (0 == len(l)): + continue + + all_defines += INDENT * 2 + "\"" + re.sub(r"[ ]+", "\",\n" + INDENT * 2 + "\"", re.sub("=\"\"", "=", l)) + "\",\n" + + return all_defines + + def getSources(self, mode): + if not mode in self.allmoduleinfo.keys(): + raise Exception("Invalid index of module info") + + buildfile = path.join(self.getBuildDir(), self.allmoduleinfo[mode].Build_Make) + with open(buildfile) as f: + text = f.read() + + lines = re.findall(".*?: .*?CMakeFiles/.*?\\.dir/.*?\\.o\\n", text) + lines = [l.replace(".o", "\",") for l in lines] + + self.adjustSources(mode, lines) + + #make source pretty + return INDENT * 2 + "".join(lines).strip() + + def getLibrary(self, mode, reg1, reg2, reg3): + if not mode in self.allmoduleinfo.keys(): + raise Exception("Invalid index of module info") + + buildfile = path.join(self.getBuildDir(), self.allmoduleinfo[mode].Build_Make) + with open(buildfile) as f: + text = f.read() + + lines = re.findall(reg1, text) + if (0 == len(lines)): + return "" + + all_lib = "" + for i, l in enumerate(lines): + if 0 == len(l) or re.search("(?<=" + self.allmoduleinfo[mode].Module_Name + reg2, l): + continue + + j = l.rfind(": ") + if 0 > j: + continue + + l = l[(j + 2):] + j = l.rfind('/') + all_lib += INDENT * 2 + "\"" + re.sub(reg3, "\",", l[(j + 1):] if 0 <= j else l) + + return all_lib \ No newline at end of file diff --git a/scripts/cleanicdloadergenerator.py b/scripts/cleanicdloadergenerator.py new file mode 100755 index 0000000..d6523a7 --- /dev/null +++ b/scripts/cleanicdloadergenerator.py @@ -0,0 +1,49 @@ +#! /usr/bin/env python3 +""" +* Copyright (c) 2019, Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +""" + +import os +import os.path as path +from androidbpgenerator import BUILD_DIR, NOVERBOSE + + +class Main: + + def run(self): + script = path.dirname(__file__) + root = path.abspath(path.join(script, "../..")) + + print("script = " + script) + print("root = " + root) + + # remove all middle & build files + print("It is removing build and middle-files for OpenCL-ICD-Loader ... ") + cmd = "rm -rf " + path.join(script, "__pycache__") + NOVERBOSE + cmd += "rm -rf " + path.join(root, BUILD_DIR) + NOVERBOSE + #cmd += "find " + path.join(script, "..") + " -name '*\.bp' -type f -delete" + NOVERBOSE + os.system(cmd) + + print("Done ! ") + + +m = Main() +m.run() \ No newline at end of file diff --git a/scripts/icdloadergenerator.py b/scripts/icdloadergenerator.py new file mode 100755 index 0000000..dc00a04 --- /dev/null +++ b/scripts/icdloadergenerator.py @@ -0,0 +1,77 @@ +#! /usr/bin/env python3 +""" +* Copyright (c) 2019, Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +""" + +import os +import os.path as path +import re +from androidbpgenerator import INDENT, CCDefaults, ModuleInfo, Generator, NOVERBOSE + +RUN_CALLABLE = True + + +class ICDLoaderGenerator(Generator): + def __init__(self, root): + # It is necessary that patching on LLVM before generating Android.bp + self.proj = path.join(root, "OpenCL-ICD-Loader/") + super(ICDLoaderGenerator, self).__init__(self.proj, root) + + self.allmoduleinfo[0] = ModuleInfo("libOpenCL", "libOpenCL.bp", "CMakeFiles/OpenCL.dir/", + "library_shared", "OpenCL-ICD-Loader-defaults") + self.allmoduleinfo[1] = ModuleInfo("libIcdLog", "libIcdLog.bp", "test/log/CMakeFiles/IcdLog.dir/", + "library_shared", "OpenCL-ICD-Loader-defaults") + self.allmoduleinfo[2] = ModuleInfo("libOpenCLDriverStub", "libOpenCLDriverStub.bp", + "test/driver_stub/CMakeFiles/OpenCLDriverStub.dir/", "library_shared", "OpenCL-ICD-Loader-defaults") + self.allmoduleinfo[3] = ModuleInfo("icd_loader_test", "icd_loader_test.bp", + "test/loader_test/CMakeFiles/icd_loader_test.dir/", "binary", "OpenCL-ICD-Loader-defaults") + + self.allmoduledefaults = CCDefaults(self.proj, "OpenCL-ICD-Loader-defaults", + cflags = ["-Wno-error", "-Wno-error=implicit-function-declaration", "-DAMD64"], + cppflags = ["-D__ANDROID__"], + clang_cflags = ["-Wno-error=non-virtual-dtor"], + include_dirs = ["hardware/intel/external/opencl/igc/include/third_party/opencl_headers"], + bpfiles = ["libOpenCL.bp", "libIcdLog.bp", "libOpenCLDriverStub.bp", "icd_loader_test.bp"], ) + + def getTemplate(self): + return "icd-loader.tpl" + + def adjustSources(self, mode, all_sources): + for i, l in enumerate(all_sources): + all_sources[i] = INDENT * 2 + "\"" + re.sub(r".*?: " + self.allmoduleinfo[mode].Mid_Dir, "", + re.sub("CMakeFiles/.*?\\.dir/", "", l.replace("__/", "../"))) + + +class Main: + + def run(self): + script = path.dirname(__file__) + root = path.abspath(path.join(script, "../..")) + + print("script = " + script) + print("root = " + root) + + ICDLoaderGenerator(root).generate() + + +if RUN_CALLABLE: + m = Main() + m.run() \ No newline at end of file From de95af5f3900281779b19e9c87f06b79292dccaa Mon Sep 17 00:00:00 2001 From: dengliqiang Date: Thu, 12 Sep 2019 20:25:43 +0800 Subject: [PATCH 3/7] Add all of bp files which are generated by script and templates for compiling. Signed-off-by: dengliqiang --- Android.bp | 40 ++++++++++++++++++++++++++++++++++ icd_loader_test.bp | 49 ++++++++++++++++++++++++++++++++++++++++++ libIcdLog.bp | 39 +++++++++++++++++++++++++++++++++ libOpenCL.bp | 42 ++++++++++++++++++++++++++++++++++++ libOpenCLDriverStub.bp | 42 ++++++++++++++++++++++++++++++++++++ 5 files changed, 212 insertions(+) create mode 100644 Android.bp create mode 100644 icd_loader_test.bp create mode 100644 libIcdLog.bp create mode 100644 libOpenCL.bp create mode 100644 libOpenCLDriverStub.bp diff --git a/Android.bp b/Android.bp new file mode 100644 index 0000000..0464fed --- /dev/null +++ b/Android.bp @@ -0,0 +1,40 @@ +cc_defaults { + name: "OpenCL-ICD-Loader-defaults", + + vendor_available: true, + + cflags: [ + "-Wno-error", + "-Wno-error=implicit-function-declaration", + "-DAMD64", + ], + + cppflags: [ + "-D__ANDROID__", + ], + + clang_cflags: [ + "-Wno-error=non-virtual-dtor", + ], + + include_dirs: [ + "hardware/intel/external/opencl/igc/include/third_party/opencl_headers", + ], + + shared_libs: [ + + ], + + static_libs: [ + + ], + +} + + +build = [ + "libOpenCL.bp", + "libIcdLog.bp", + "libOpenCLDriverStub.bp", + "icd_loader_test.bp", +] \ No newline at end of file diff --git a/icd_loader_test.bp b/icd_loader_test.bp new file mode 100644 index 0000000..3dc4982 --- /dev/null +++ b/icd_loader_test.bp @@ -0,0 +1,49 @@ +cc_binary { + name: "icd_loader_test", + + vendor_available: true, + + defaults: [ + "OpenCL-ICD-Loader-defaults", + ], + + srcs: [ + "test/loader_test/test_kernel.c", + "test/loader_test/main.c", + "test/loader_test/test_platforms.c", + "test/loader_test/icd_test_match.c", + "test/loader_test/test_program_objects.c", + "test/loader_test/test_sampler_objects.c", + "test/loader_test/test_buffer_object.c", + "test/loader_test/test_cl_runtime.c", + "test/loader_test/callbacks.c", + "test/loader_test/test_create_calls.c", + "test/loader_test/test_clgl.c", + "test/loader_test/test_image_objects.c", + ], + + cflags: [ + "-O3", + "-DNDEBUG", + "-DCL_TARGET_OPENCL_VERSION=220", + ], + + cppflags: [ + + ], + + local_include_dirs: [ + "inc", + "test/inc", + ], + + shared_libs: [ + "libOpenCL", + "libIcdLog", + ], + + static_libs: [ + + ], + +} \ No newline at end of file diff --git a/libIcdLog.bp b/libIcdLog.bp new file mode 100644 index 0000000..761437c --- /dev/null +++ b/libIcdLog.bp @@ -0,0 +1,39 @@ +cc_library_shared { + name: "libIcdLog", + + vendor_available: true, + + defaults: [ + "OpenCL-ICD-Loader-defaults", + ], + + srcs: [ + "test/log/icd_test_log.c", + ], + + cflags: [ + "-O3", + "-DNDEBUG", + "-fPIC", + "-DCL_TARGET_OPENCL_VERSION=220", + "-DIcdLog_EXPORTS", + ], + + cppflags: [ + + ], + + local_include_dirs: [ + "inc", + "test/inc", + ], + + shared_libs: [ + + ], + + static_libs: [ + + ], + +} \ No newline at end of file diff --git a/libOpenCL.bp b/libOpenCL.bp new file mode 100644 index 0000000..1b6cd27 --- /dev/null +++ b/libOpenCL.bp @@ -0,0 +1,42 @@ +cc_library_shared { + name: "libOpenCL", + + vendor_available: true, + + defaults: [ + "OpenCL-ICD-Loader-defaults", + ], + + srcs: [ + "loader/icd.c", + "loader/icd_dispatch.c", + "loader/linux/icd_linux.c", + "loader/linux/icd_linux_envvars.c", + ], + + cflags: [ + "-O3", + "-DNDEBUG", + "-fPIC", + "-DCL_TARGET_OPENCL_VERSION=220", + "-DOpenCL_EXPORTS", + ], + + cppflags: [ + + ], + + local_include_dirs: [ + "inc", + "loader", + ], + + shared_libs: [ + + ], + + static_libs: [ + + ], + +} \ No newline at end of file diff --git a/libOpenCLDriverStub.bp b/libOpenCLDriverStub.bp new file mode 100644 index 0000000..59f5d1a --- /dev/null +++ b/libOpenCLDriverStub.bp @@ -0,0 +1,42 @@ +cc_library_shared { + name: "libOpenCLDriverStub", + + vendor_available: true, + + defaults: [ + "OpenCL-ICD-Loader-defaults", + ], + + srcs: [ + "test/driver_stub/cl.c", + "test/driver_stub/cl_ext.c", + "test/driver_stub/cl_gl.c", + "test/driver_stub/icd.c", + ], + + cflags: [ + "-O3", + "-DNDEBUG", + "-fPIC", + "-DCL_TARGET_OPENCL_VERSION=220", + "-DOpenCLDriverStub_EXPORTS", + ], + + cppflags: [ + + ], + + local_include_dirs: [ + "inc", + "test/inc", + ], + + shared_libs: [ + "libIcdLog", + ], + + static_libs: [ + + ], + +} \ No newline at end of file From 094714453d36b0277ea45598be878e7026434f43 Mon Sep 17 00:00:00 2001 From: dengliqiang Date: Wed, 18 Sep 2019 00:32:25 +0800 Subject: [PATCH 4/7] corrected the path of 'opencl_headers' --- Android.bp | 2 +- scripts/icdloadergenerator.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Android.bp b/Android.bp index 0464fed..3788ac3 100644 --- a/Android.bp +++ b/Android.bp @@ -18,7 +18,7 @@ cc_defaults { ], include_dirs: [ - "hardware/intel/external/opencl/igc/include/third_party/opencl_headers", + "hardware/intel/external/opencl/compute-runtime/third_party/opencl_headers", ], shared_libs: [ diff --git a/scripts/icdloadergenerator.py b/scripts/icdloadergenerator.py index dc00a04..62a634f 100755 --- a/scripts/icdloadergenerator.py +++ b/scripts/icdloadergenerator.py @@ -48,7 +48,7 @@ def __init__(self, root): cflags = ["-Wno-error", "-Wno-error=implicit-function-declaration", "-DAMD64"], cppflags = ["-D__ANDROID__"], clang_cflags = ["-Wno-error=non-virtual-dtor"], - include_dirs = ["hardware/intel/external/opencl/igc/include/third_party/opencl_headers"], + include_dirs = ["hardware/intel/external/opencl/compute-runtime/third_party/opencl_headers"], bpfiles = ["libOpenCL.bp", "libIcdLog.bp", "libOpenCLDriverStub.bp", "icd_loader_test.bp"], ) def getTemplate(self): From d165ea2574f5358549c53416762e3998aed93f24 Mon Sep 17 00:00:00 2001 From: dengliqiang Date: Wed, 18 Sep 2019 00:37:38 +0800 Subject: [PATCH 5/7] cleaned redundant comment and updated printing message --- bp/icd-loader.tpl | 27 --------------------------- scripts/cleanicdloadergenerator.py | 4 ++-- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/bp/icd-loader.tpl b/bp/icd-loader.tpl index 6b537e1..718160a 100755 --- a/bp/icd-loader.tpl +++ b/bp/icd-loader.tpl @@ -18,33 +18,6 @@ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. # -# The file-tree of OpenCL-ICD-Loader -# OpenCL-ICD-Loader (cmake -DCMAKE_BUILD_TYPE=Release OpenCL-ICD-Loader) -# | -# +---- libOpenCL.so.1.2 -> Tools/Android/build/icd-loader/CMakeFiles/OpenCL.dir -# | -# +---- test -# | -# +---- log -# | | -# | +---- libIcdLog.so -> Tools/Android/build/icd-loader/test/platform/CMakeFiles/IcdLog.dir -# | -# +---- loader_test -# | | -# | +---- icd_loader_test -> Tools/Android/build/icd-loader/test/loader_test/CMakeFiles/icd_loader_test.dir -# | | -# | => libOpenCL.so.1.2, libIcdLog.so -# | -# +---- driver_stub -# | -# +---- libOpenCLDriverStub.so -> Tools/Android/build/icd-loader/test/driver_stub/CMakeFiles/OpenCLDriverStub.dir -# | -# => libIcdLog.so -# -# About the detailed of soong-build-tools(cc package), please refer to: -# https://ci.android.com/builds/submitted/5357401/linux/latest/view/soong_build.html -# -# # library_static, library_shared, binary cc_@module { name: "@name", diff --git a/scripts/cleanicdloadergenerator.py b/scripts/cleanicdloadergenerator.py index d6523a7..818363f 100755 --- a/scripts/cleanicdloadergenerator.py +++ b/scripts/cleanicdloadergenerator.py @@ -35,8 +35,8 @@ def run(self): print("script = " + script) print("root = " + root) - # remove all middle & build files - print("It is removing build and middle-files for OpenCL-ICD-Loader ... ") + # remove all intermediate files and building directories + print("It is removing building directories and intermediate files for OpenCL-ICD-Loader ... ") cmd = "rm -rf " + path.join(script, "__pycache__") + NOVERBOSE cmd += "rm -rf " + path.join(root, BUILD_DIR) + NOVERBOSE #cmd += "find " + path.join(script, "..") + " -name '*\.bp' -type f -delete" + NOVERBOSE From 6bfa68104ef5547b660ee0bbecca6c1cc90b67e7 Mon Sep 17 00:00:00 2001 From: Wan Shuang Date: Thu, 12 Mar 2020 14:08:58 +0800 Subject: [PATCH 6/7] Upgraded Python2 scripts Upgraded Python2 scripts to Python 3 using 2to3 tool. This is to mitigrate security risks of Python2 deprecation. Signed-off-by: Wan Shuang Tracked-On: OAM-90214 --- scripts/androidbpgenerator.py | 16 ++++++++-------- scripts/cleanicdloadergenerator.py | 4 ++-- scripts/icdloadergenerator.py | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/androidbpgenerator.py b/scripts/androidbpgenerator.py index 2ff92b8..98587be 100755 --- a/scripts/androidbpgenerator.py +++ b/scripts/androidbpgenerator.py @@ -134,7 +134,7 @@ def generate(self, to_cmake = True, to_make = False): allBPs = {} # sub-module" .bp - for k in self.allmoduleinfo.keys(): + for k in list(self.allmoduleinfo.keys()): # the path of Android.bp bp = path.normpath(path.join(self.src, self.allmoduleinfo[k].Bp_File_Name)) # read template @@ -143,20 +143,20 @@ def generate(self, to_cmake = True, to_make = False): # remove all comment tpl = re.sub("#.*\n", "", tpl).strip() # an Android.bp is related to some module - if bp in allBPs.keys(): + if bp in list(allBPs.keys()): allBPs[bp] += "\n\n" + self.replaceTemplate(k, tpl) else: allBPs[bp] = self.replaceTemplate(k, tpl) # Android.bp allBPs[self.allmoduledefaults.getBpFilePath()] = self.allmoduledefaults.generate() - for bp in allBPs.keys(): + for bp in list(allBPs.keys()): # remove old Android.bp remove(bp) # create new Android.bp with open(bp, "w") as f: f.write(allBPs[bp]) - print(bp + " has been generated.") + print((bp + " has been generated.")) #virtuall functions def getTemplate(self): @@ -217,7 +217,7 @@ def generateMakefile(self, debug=False, make=False): cmd += "cd " + builddir + " && " + self.getCmakeCmd() + verbose # need to make this project if make: - print("It is making: " + self.src) + print(("It is making: " + self.src)) cmd += "make -j$(nproc)" os.system(cmd) @@ -246,7 +246,7 @@ def getIncludes(self, mode, title): return "\n".join(includesfile) if includesfile else "" def getDefines(self, mode, title): - if not mode in self.allmoduleinfo.keys(): + if not mode in list(self.allmoduleinfo.keys()): raise Exception("Invalid index of module info") flagsfile = path.join(self.getBuildDir(), self.allmoduleinfo[mode].Flags_Make) @@ -270,7 +270,7 @@ def getDefines(self, mode, title): return all_defines def getSources(self, mode): - if not mode in self.allmoduleinfo.keys(): + if not mode in list(self.allmoduleinfo.keys()): raise Exception("Invalid index of module info") buildfile = path.join(self.getBuildDir(), self.allmoduleinfo[mode].Build_Make) @@ -286,7 +286,7 @@ def getSources(self, mode): return INDENT * 2 + "".join(lines).strip() def getLibrary(self, mode, reg1, reg2, reg3): - if not mode in self.allmoduleinfo.keys(): + if not mode in list(self.allmoduleinfo.keys()): raise Exception("Invalid index of module info") buildfile = path.join(self.getBuildDir(), self.allmoduleinfo[mode].Build_Make) diff --git a/scripts/cleanicdloadergenerator.py b/scripts/cleanicdloadergenerator.py index 818363f..63cd24d 100755 --- a/scripts/cleanicdloadergenerator.py +++ b/scripts/cleanicdloadergenerator.py @@ -32,8 +32,8 @@ def run(self): script = path.dirname(__file__) root = path.abspath(path.join(script, "../..")) - print("script = " + script) - print("root = " + root) + print(("script = " + script)) + print(("root = " + root)) # remove all intermediate files and building directories print("It is removing building directories and intermediate files for OpenCL-ICD-Loader ... ") diff --git a/scripts/icdloadergenerator.py b/scripts/icdloadergenerator.py index 62a634f..012bff6 100755 --- a/scripts/icdloadergenerator.py +++ b/scripts/icdloadergenerator.py @@ -66,8 +66,8 @@ def run(self): script = path.dirname(__file__) root = path.abspath(path.join(script, "../..")) - print("script = " + script) - print("root = " + root) + print(("script = " + script)) + print(("root = " + root)) ICDLoaderGenerator(root).generate() From 3cfd125078c88a3af8c37a0a44a602d87a785522 Mon Sep 17 00:00:00 2001 From: Wan Shuang Date: Sun, 16 Aug 2020 17:36:12 +0800 Subject: [PATCH 7/7] Make the libOpenCL accessible to vendor domain only. Ensure vendor domain could access the openCL share libraries at runtime. Change-Id: I7e351d98832e74bb4164a3cad863334b95b53732 Tracked-On: OAM-92070 Signed-off-by: Wan Shuang --- Android.bp | 4 ++-- bp/defaults.tpl | 4 ++-- bp/icd-loader.tpl | 4 ++-- icd_loader_test.bp | 4 ++-- libIcdLog.bp | 4 ++-- libOpenCL.bp | 4 ++-- libOpenCLDriverStub.bp | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Android.bp b/Android.bp index 3788ac3..dadf466 100644 --- a/Android.bp +++ b/Android.bp @@ -1,7 +1,7 @@ cc_defaults { name: "OpenCL-ICD-Loader-defaults", - vendor_available: true, + vendor: true, cflags: [ "-Wno-error", @@ -37,4 +37,4 @@ build = [ "libIcdLog.bp", "libOpenCLDriverStub.bp", "icd_loader_test.bp", -] \ No newline at end of file +] diff --git a/bp/defaults.tpl b/bp/defaults.tpl index 9730967..eb5c087 100755 --- a/bp/defaults.tpl +++ b/bp/defaults.tpl @@ -21,7 +21,7 @@ cc_defaults { name: "@name", - vendor_available: true, + vendor: true, cflags: [ @cflags @@ -52,4 +52,4 @@ cc_defaults { build = [ @build -] \ No newline at end of file +] diff --git a/bp/icd-loader.tpl b/bp/icd-loader.tpl index 718160a..5c6632e 100755 --- a/bp/icd-loader.tpl +++ b/bp/icd-loader.tpl @@ -22,7 +22,7 @@ cc_@module { name: "@name", - vendor_available: true, + vendor: true, defaults: [ @defaults @@ -52,4 +52,4 @@ cc_@module { @static_libs ], -} \ No newline at end of file +} diff --git a/icd_loader_test.bp b/icd_loader_test.bp index 3dc4982..e60a3d7 100644 --- a/icd_loader_test.bp +++ b/icd_loader_test.bp @@ -1,7 +1,7 @@ cc_binary { name: "icd_loader_test", - vendor_available: true, + vendor: true, defaults: [ "OpenCL-ICD-Loader-defaults", @@ -46,4 +46,4 @@ cc_binary { ], -} \ No newline at end of file +} diff --git a/libIcdLog.bp b/libIcdLog.bp index 761437c..d8f28cf 100644 --- a/libIcdLog.bp +++ b/libIcdLog.bp @@ -1,7 +1,7 @@ cc_library_shared { name: "libIcdLog", - vendor_available: true, + vendor: true, defaults: [ "OpenCL-ICD-Loader-defaults", @@ -36,4 +36,4 @@ cc_library_shared { ], -} \ No newline at end of file +} diff --git a/libOpenCL.bp b/libOpenCL.bp index 1b6cd27..b677a8f 100644 --- a/libOpenCL.bp +++ b/libOpenCL.bp @@ -1,7 +1,7 @@ cc_library_shared { name: "libOpenCL", - vendor_available: true, + vendor: true, defaults: [ "OpenCL-ICD-Loader-defaults", @@ -39,4 +39,4 @@ cc_library_shared { ], -} \ No newline at end of file +} diff --git a/libOpenCLDriverStub.bp b/libOpenCLDriverStub.bp index 59f5d1a..bb8d283 100644 --- a/libOpenCLDriverStub.bp +++ b/libOpenCLDriverStub.bp @@ -1,7 +1,7 @@ cc_library_shared { name: "libOpenCLDriverStub", - vendor_available: true, + vendor: true, defaults: [ "OpenCL-ICD-Loader-defaults", @@ -39,4 +39,4 @@ cc_library_shared { ], -} \ No newline at end of file +}