[PATCH v3 1/2] amdgpu/math: Don't use llvm instrinsic for native_log

AMDGPU targets don't have insturction for it,
so it'll be expanded to C * log2 anyway.

v2: use native_log2 instead of the more precise sw implementation
v3: move to amdgpu

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>

Use llvm instrinsic by default
Provide amdgpu workaround

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>

Use llvm instrinsic by default
Provide amdgpu workaround

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
---
This is the last missing native_builtin.

ping.

Jan

Use llvm instrinsic by default
Provide amdgpu workaround

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>

This is the last missing native_builtin.

ping.

Jan

amdgpu/lib/SOURCES | 1 +
amdgpu/lib/math/native_log10.cl | 27 ++++++++++++++++++++++++++
amdgpu/lib/math/native_log10.inc | 25 ++++++++++++++++++++++++
generic/include/clc/clc.h | 1 +
generic/include/clc/math/native_log10.h | 27 ++++++++++++++++++++++++++
generic/include/clc/math/native_log10.inc | 23 ++++++++++++++++++++++
generic/lib/SOURCES | 1 +
generic/lib/math/native_log10.cl | 32 +++++++++++++++++++++++++++++++
generic/lib/math/native_log10.inc | 25 ++++++++++++++++++++++++
9 files changed, 162 insertions(+)
create mode 100644 amdgpu/lib/math/native_log10.cl
create mode 100644 amdgpu/lib/math/native_log10.inc
create mode 100644 generic/include/clc/math/native_log10.h
create mode 100644 generic/include/clc/math/native_log10.inc
create mode 100644 generic/lib/math/native_log10.cl
create mode 100644 generic/lib/math/native_log10.inc

diff --git a/amdgpu/lib/SOURCES b/amdgpu/lib/SOURCES
index 8cbe1d4…59d8b22 100644
— a/amdgpu/lib/SOURCES
+++ b/amdgpu/lib/SOURCES
@@ -1,3 +1,4 @@
math/native_log.cl
+math/native_log10.cl
math/nextafter.cl
math/sqrt.cl
diff --git a/amdgpu/lib/math/native_log10.cl b/amdgpu/lib/math/native_log10.cl
new file mode 100644
index 0000000…619b634
— /dev/null
+++ b/amdgpu/lib/math/native_log10.cl
@@ -0,0 +1,27 @@
+/*

    • Copyright (c) 2014,2015 Advanced Micro Devices, Inc.

I think you should probably remove these copyright statements, or at least replace them with the standard LLVM copyright notice.

Patch looks good otherwise. No need to send a version 2.

–Aaron

AMDGPU targets don't have insturction for it,
so it'll be expanded to C * log2 anyway.

v2: use native_log2 instead of the more precise sw implementation
v3: move to amdgpu

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
---
amdgpu/lib/SOURCES | 1 +
amdgpu/lib/math/native_log.cl | 27 +++++++++++++++++++++++++++
amdgpu/lib/math/native_log.inc | 25 +++++++++++++++++++++++++
3 files changed, 53 insertions(+)
create mode 100644 amdgpu/lib/math/native_log.cl
create mode 100644 amdgpu/lib/math/native_log.inc

diff --git a/amdgpu/lib/SOURCES b/amdgpu/lib/SOURCES
index ce5fe66..8cbe1d4 100644
--- a/amdgpu/lib/SOURCES
+++ b/amdgpu/lib/SOURCES
@@ -1,2 +1,3 @@
+math/native_log.cl
math/nextafter.cl
math/sqrt.cl
diff --git a/amdgpu/lib/math/native_log.cl b/amdgpu/lib/math/native_log.cl
new file mode 100644
index 0000000..f8ba08f
--- /dev/null
+++ b/amdgpu/lib/math/native_log.cl
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2014,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>
+
+#define __CLC_BODY <native_log.inc>
+#define __FLOAT_ONLY
+#include <clc/math/gentype.inc>
diff --git a/amdgpu/lib/math/native_log.inc b/amdgpu/lib/math/native_log.inc
new file mode 100644
index 0000000..d4950c2
--- /dev/null
+++ b/amdgpu/lib/math/native_log.inc
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2014,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_OVERLOAD _CLC_DEF __CLC_GENTYPE native_log(__CLC_GENTYPE val) {
+ return native_log2(val) * (1.0f / M_LOG2E_F);

Looks ok to me.

But similar to the other patch in this 2-part series, you can probably
exclude the AMD copyright statement since you're the author here.

--Aaron

I had exactly the same thing locally for a while, so I can say this is good.

Reviewed-by: Vedran Miletić <vedran@miletic.net>