[libclc] r235329 - configure: Add --enable-runtime-subnormal option

Tom Stellard thomas.stellard at amd.com
Mon Apr 20 11:49:50 PDT 2015


Author: tstellar
Date: Mon Apr 20 13:49:50 2015
New Revision: 235329

URL: http://llvm.org/viewvc/llvm-project?rev=235329&view=rev
Log:
configure: Add --enable-runtime-subnormal option

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();

Added:
    libclc/trunk/generic/include/config.h
    libclc/trunk/generic/lib/subnormal_config.cl
    libclc/trunk/generic/lib/subnormal_disable.ll
    libclc/trunk/generic/lib/subnormal_helper_func.ll
    libclc/trunk/generic/lib/subnormal_use_default.ll
Modified:
    libclc/trunk/configure.py
    libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/configure.py
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/configure.py?rev=235329&r1=235328&r2=235329&view=diff
==============================================================================
--- libclc/trunk/configure.py (original)
+++ libclc/trunk/configure.py Mon Apr 20 13:49:50 2015
@@ -34,6 +34,8 @@ p.add_option('--pkgconfigdir', metavar='
              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.pat
 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')

Added: libclc/trunk/generic/include/config.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/config.h?rev=235329&view=auto
==============================================================================
--- libclc/trunk/generic/include/config.h (added)
+++ libclc/trunk/generic/include/config.h Mon Apr 20 13:49:50 2015
@@ -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();

Modified: libclc/trunk/generic/lib/SOURCES
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=235329&r1=235328&r2=235329&view=diff
==============================================================================
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Mon Apr 20 13:49:50 2015
@@ -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

Added: libclc/trunk/generic/lib/subnormal_config.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/subnormal_config.cl?rev=235329&view=auto
==============================================================================
--- libclc/trunk/generic/lib/subnormal_config.cl (added)
+++ libclc/trunk/generic/lib/subnormal_config.cl Mon Apr 20 13:49:50 2015
@@ -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();
+}

Added: libclc/trunk/generic/lib/subnormal_disable.ll
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/subnormal_disable.ll?rev=235329&view=auto
==============================================================================
--- libclc/trunk/generic/lib/subnormal_disable.ll (added)
+++ libclc/trunk/generic/lib/subnormal_disable.ll Mon Apr 20 13:49:50 2015
@@ -0,0 +1 @@
+ at __CLC_SUBNORMAL_DISABLE = unnamed_addr constant i1 true

Added: libclc/trunk/generic/lib/subnormal_helper_func.ll
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/subnormal_helper_func.ll?rev=235329&view=auto
==============================================================================
--- libclc/trunk/generic/lib/subnormal_helper_func.ll (added)
+++ libclc/trunk/generic/lib/subnormal_helper_func.ll Mon Apr 20 13:49:50 2015
@@ -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 }

Added: libclc/trunk/generic/lib/subnormal_use_default.ll
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/subnormal_use_default.ll?rev=235329&view=auto
==============================================================================
--- libclc/trunk/generic/lib/subnormal_use_default.ll (added)
+++ libclc/trunk/generic/lib/subnormal_use_default.ll Mon Apr 20 13:49:50 2015
@@ -0,0 +1 @@
+ at __CLC_SUBNORMAL_DISABLE = unnamed_addr constant i1 false





More information about the cfe-commits mailing list