[Libclc-dev] [PATCH 04/15] configure: Add --enable-runtime-subnormal option
Tom Stellard
thomas.stellard at amd.com
Tue Apr 7 11:05:35 PDT 2015
This makes it possible for runtime implementations to disable
subnormal handling at runtime.
When this flag is enabled, decisions about how to handle subnormals
in the library will be controlled by an external variable called
__CLC_SUBNORMAL_DISABLE.
Function implementations should use these new helpers for querying subnormal
support:
__clc_fp16_subnormals_supported();
__clc_fp32_subnormals_supported();
__clc_fp64_subnormals_supported();
In order for the library to link correctly with this feature,
users will be required to either:
1. Insert this variable into the module (if using the LLVM/Clang C++/C APIs).
2. Pass either subnormal_disable.bc or subnormal_use_default.bc to the
linker. These files are distributed with liblclc and installed to
$(installdir). e.g.:
llvm-link -o kernel-out.bc kernel.bc builtins-nosubnormal.bc subnormal_disable.bc
or
llvm-link -o kernel-out.bc kernel.bc builtins-nosubnormal.bc subnormal_use_default.bc
If you do not supply the --enable-runtime-subnormal then the library
behaves the same as it did before this commit.
In addition to these changes, the patch adds helper functions that
should be used when implementing library functions that need
special handling for denormals:
__clc_fp16_subnormals_supported();
__clc_fp32_subnormals_supported();
__clc_fp64_subnormals_supported();
---
configure.py | 16 ++++++++++++++++
generic/include/config.h | 26 +++++++++++++++++++++++++
generic/lib/SOURCES | 2 ++
generic/lib/subnormal_config.cl | 37 ++++++++++++++++++++++++++++++++++++
generic/lib/subnormal_disable.ll | 1 +
generic/lib/subnormal_helper_func.ll | 8 ++++++++
generic/lib/subnormal_use_default.ll | 1 +
7 files changed, 91 insertions(+)
create mode 100644 generic/include/config.h
create mode 100644 generic/lib/subnormal_config.cl
create mode 100644 generic/lib/subnormal_disable.ll
create mode 100644 generic/lib/subnormal_helper_func.ll
create mode 100644 generic/lib/subnormal_use_default.ll
diff --git a/configure.py b/configure.py
index 602165b..7d4b537 100755
--- a/configure.py
+++ b/configure.py
@@ -34,6 +34,8 @@ p.add_option('--pkgconfigdir', metavar='PATH',
help='install clc.pc to given dir')
p.add_option('-g', metavar='GENERATOR', default='make',
help='use given generator (default: make)')
+p.add_option('--enable-runtime-subnormal', action="store_true", default=False,
+ help='Allow runtimes to choose subnormal support')
(options, args) = p.parse_args()
llvm_config_exe = options.with_llvm_config or "llvm-config"
@@ -133,6 +135,16 @@ manifest_deps = set([sys.argv[0], os.path.join(srcdir, 'build', 'metabuild.py'),
install_files_bc = []
install_deps = []
+# Create rules for subnormal helper objects
+for src in ['subnormal_disable.ll', 'subnormal_use_default.ll']:
+ obj_name = src[:-2] + 'bc'
+ obj = os.path.join('generic--', 'lib', obj_name)
+ src_file = os.path.join('generic', 'lib', src)
+ b.build(obj, 'LLVM_AS', src_file)
+ b.default(obj)
+ install_files_bc.append((obj, obj))
+ install_deps.append(obj)
+
# Create libclc.pc
clc = open('libclc.pc', 'w')
clc.write('includedir=%(inc)s\nlibexecdir=%(lib)s\n\nName: libclc\nDescription: Library requirements of the OpenCL C programming language\nVersion: %(maj)s.%(min)s.%(pat)s\nCflags: -I${includedir}\nLibs: -L${libexecdir}' %
@@ -209,6 +221,10 @@ for target in targets:
else:
b.build(obj, clang_bc_rule, src_file)
+ obj = os.path.join('generic--', 'lib', 'subnormal_use_default.bc')
+ if not options.enable_runtime_subnormal:
+ objects.append(obj)
+
builtins_link_bc = os.path.join(target, 'lib', 'builtins.link' + obj_suffix + '.bc')
builtins_opt_bc = os.path.join(target, 'lib', 'builtins.opt' + obj_suffix + '.bc')
builtins_bc = os.path.join('built_libs', full_target_name + '.bc')
diff --git a/generic/include/config.h b/generic/include/config.h
new file mode 100644
index 0000000..2994199
--- /dev/null
+++ b/generic/include/config.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2015 Advanced Micro Devices, Inc.
+ *
+ * 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.
+ */
+
+_CLC_DECL bool __clc_subnormals_disabled();
+_CLC_DECL bool __clc_fp16_subnormals_supported();
+_CLC_DECL bool __clc_fp32_subnormals_supported();
+_CLC_DECL bool __clc_fp64_subnormals_supported();
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index a4a017a..d7caa78 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -1,3 +1,5 @@
+subnormal_config.cl
+subnormal_helper_func.ll
async/async_work_group_copy.cl
async/async_work_group_strided_copy.cl
async/prefetch.cl
diff --git a/generic/lib/subnormal_config.cl b/generic/lib/subnormal_config.cl
new file mode 100644
index 0000000..4bcecfd
--- /dev/null
+++ b/generic/lib/subnormal_config.cl
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015 Advanced Micro Devices, Inc.
+ *
+ * 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.
+ */
+
+#include <clc/clc.h>
+
+#include "config.h"
+
+_CLC_DEF bool __clc_fp16_subnormals_supported() {
+ return false;
+}
+
+_CLC_DEF bool __clc_fp32_subnormals_supported() {
+ return false;
+}
+
+_CLC_DEF bool __clc_fp64_subnormals_supported() {
+ return !__clc_subnormals_disabled();
+}
diff --git a/generic/lib/subnormal_disable.ll b/generic/lib/subnormal_disable.ll
new file mode 100644
index 0000000..b935583
--- /dev/null
+++ b/generic/lib/subnormal_disable.ll
@@ -0,0 +1 @@
+ at __CLC_SUBNORMAL_DISABLE = unnamed_addr constant i1 true
diff --git a/generic/lib/subnormal_helper_func.ll b/generic/lib/subnormal_helper_func.ll
new file mode 100644
index 0000000..fb1b5d2
--- /dev/null
+++ b/generic/lib/subnormal_helper_func.ll
@@ -0,0 +1,8 @@
+ at __CLC_SUBNORMAL_DISABLE = external global i1
+
+define i1 @__clc_subnormals_disabled() #0 {
+ %disable = load i1, i1* @__CLC_SUBNORMAL_DISABLE
+ ret i1 %disable
+}
+
+attributes #0 = { alwaysinline }
diff --git a/generic/lib/subnormal_use_default.ll b/generic/lib/subnormal_use_default.ll
new file mode 100644
index 0000000..d70c63b
--- /dev/null
+++ b/generic/lib/subnormal_use_default.ll
@@ -0,0 +1 @@
+ at __CLC_SUBNORMAL_DISABLE = unnamed_addr constant i1 false
--
2.0.4
More information about the Libclc-dev
mailing list