Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8329816: Add SLEEF version 3.6.1 #19185

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
84 changes: 84 additions & 0 deletions make/devkit/createSleef.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash
#
# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

# This script cross-compiles SLEEF for a non-native platform. For example,
# it can be used to build the aarch64 inline headers on an x64 machine by
# doing something like:
#
# 1. cd <sleef>
# 2. bash <jdk>/make/devkit/createSleef.sh aarch64-gcc.cmake <path-to>/devkit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you'd need a different copy of sleef for each platform? The files you have put in linux/native/libvectormath, what platform are they for? Should we not put them in a platform-specific subdirectory?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you'd need a different copy of sleef for each platform?

I think it's one or more.

The files you have put in linux/native/libvectormath, what platform are they for? Should we not put them in a platform-specific subdirectory?

we could, but not necessary, as long as they have different suffixes, and normally that suffixes indicate what platform it's for.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, suffix works fine too. But the files currently in the patch is named e.g. sleefinline_advsimd.h, which does not indicate any platform at all. Is it a generic file, and the platform specific ones are still missing from this PR?

Copy link

@Hamlin-Li Hamlin-Li May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both sleefinline_advsimd.h and sleefinline_sve.h are specific for arm.
In the future, on riscv the corresponding file name will be sleefinline_rvvm1.h.

Only misc.h is a generic file shared among platforms.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you mean that the sve suffix signals that it is for ARM. I thought you were talking about having a name like sleefinline_aarch64.h.

Sure, if the only files generated by sleef are ever .h files, the logic for chosing which to include can be done entirely by #ifdefs in the source code. But if there ever needs to be different .c or .cpp files to include in the build, the build system needs to be able to determine automatically if they should be included or included, and that can only be made if the path or the file name includes the CPU moniker.

Personally, I think it would show good alignment with the prevailing norms in the JDK to also use this way of naming files for .h files. But I confess that for .h files it is more a matter of style, rather than a necessity from the build system.

Copy link

@Hamlin-Li Hamlin-Li May 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the information. I think the files from sleef will be .h headers only. I'm also fine to align with prevailing norms in the JDK, it's always good to do so.

Just a reminder for us in the future discussion of #18605, maybe we should consider this dir or file naming norms (e.g. currently there are vector_math_sve.c and vector_math_neon.c under src/jdk.incubator.vector/linux/native/libvectormath), as there will be more files related to different platforms added in the future, e.g. riscv64.

#
# The second argument (the devkit path) should point to the devkit
# directory in which devkit.info resides.
#
# After the build completes, the build result is available in the
# <jdk>/build/sleef/build/cross directory. For example, the aarch64
# header files can be found in:
#
# <jdk>/build/sleef/cross/include/sleefinline_{advsimd,sve}.h
#

SCRIPT_DIR="$(cd "$(dirname $0)" > /dev/null && pwd)"
BUILD_DIR="${SCRIPT_DIR}/../../build/sleef"

set -eu

if [ ! $# = 2 ]; then
echo "Usage: $0 <cmake toolchain file> <devkit>"
exit 1
fi

CMAKE_TOOLCHAIN_FILE="$1"
DEVKIT_ROOT="$2"

if [ ! -f "${CMAKE_TOOLCHAIN_FILE}" ]; then
echo "Failed to locate ${CMAKE_TOOLCHAIN_FILE}"
exit 1
fi

DEVKIT_INFO="${DEVKIT_ROOT}/devkit.info"
if [ ! -f "${DEVKIT_INFO}" ]; then
echo "Failed to locate ${DEVKIT_INFO}"
exit 1
fi

. "${DEVKIT_INFO}"

export PATH="${PATH}:${DEVKIT_EXTRA_PATH}"

BUILD_NATIVE_DIR="${BUILD_DIR}/native"
BUILD_CROSS_DIR="${BUILD_DIR}/cross"

mkdir -p "${BUILD_NATIVE_DIR}"
cmake -S . -B "${BUILD_NATIVE_DIR}"
cmake --build "${BUILD_NATIVE_DIR}" -j

mkdir -p "${BUILD_CROSS_DIR}"
cmake -S . -B "${BUILD_CROSS_DIR}" \
-DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOLCHAIN_FILE}" \
-DNATIVE_BUILD_DIR="${BUILD_NATIVE_DIR}" \
-DSLEEF_BUILD_INLINE_HEADERS=TRUE
cmake --build "${BUILD_CROSS_DIR}" -j
34 changes: 34 additions & 0 deletions src/jdk.incubator.vector/linux/legal/sleef.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## SLEEF v3.6

### Notice
```
Copyright © 2010-2024 SLEEF Project, Naoki Shibata and contributors
```

### LICENSE
```

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this missing line break a mistake or intended?


```
32 changes: 32 additions & 0 deletions src/jdk.incubator.vector/linux/native/libvectormath/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Maintenance notes for importing SLEEF source code

## Motivation
When importing files from SLEEF, please follow below steps.

## Steps of maintenance

### Step 1: Clone the SLEEF repository
Location: https://github.com/shibatch/sleef

### Step 2: Build SLEEF
There's a `make/devkit/createSleef.sh` helper script which can be used to build SLEEF. In particular, it includes cross-compilation functionality.

If not using the helper script, the build steps can be found here: https://github.com/shibatch/sleef?tab=readme-ov-file#how-to-build-sleef

NOTE: The following cmake options are necessary when building SLEEF:
* -DSLEEF_BUILD_INLINE_HEADERS=ON
* -DSLEEF_ENFORCE_SVE=ON

### Step 3: Import the SLEEF files into the JDK
SLEEF source and generated source:
* ${SLEEF_SRC_DIR}/common/misc.h
* ${SLEEF_BUILD_DIR}/include/sleefinline_advsimd.h
* ${SLEEF_BUILD_DIR}/include/sleefinline_sve.h

JDK target dir:
* ${JDK_SRC_DIR}/jdk.incubator.vector/linux/native/libvectormath/

### Step 4: Make necessary changes to resolve any build issues in case there is any

Currently, the only necessary change is:
* make `Sleef_rempitabdp` and `Sleef_rempitabsp` in sleefinline_advsimd.h and sleefinline_sve.h `static` to avoid multiple definitions.