-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
68 changed files
with
5,106 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
### IDE | ||
.idea/ | ||
|
||
### Gradle | ||
.gradle/ | ||
.kotlin/ | ||
build/ | ||
|
||
### CMake | ||
cmake-build-*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
3-Clause BSD NON-AI License | ||
|
||
Copyright 2024 Martmists | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer | ||
in the documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
|
||
4. The source code and the binary form, and any modifications made to them may not be used for the purpose of training or improving machine learning algorithms, | ||
including but not limited to artificial intelligence, natural language processing, or data mining. This condition applies to any derivatives, | ||
modifications, or updates based on the Software code. Any usage of the source code or the binary form in an AI-training dataset is considered a breach of this License. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# NDArray.SIMD | ||
|
||
A Kotlin NDArray library with built-in SIMD support. | ||
|
||
### Installation | ||
|
||
Coming soon:tm: to my Maven repo. | ||
|
||
### Motivation | ||
|
||
I basically made this because [Viktor](https://github.com/JetBrains-Research/viktor) didn't really utilize their SIMD capabilities. | ||
|
||
As such, most of the JVM code for NDArray is mostly the same as Viktor. | ||
|
||
### License | ||
|
||
The nativeMain and jvmMain sourcesets are licensed under the [3-Clause BSD NON-AI License](https://github.com/non-ai-licenses/non-ai-licenses/blob/main/NON-AI-BSD3), with @Martmists-GH as the copyright holder. | ||
|
||
The commonMain sourceset is mostly copied/adapted from Viktor, and as such is licensed under the [original MIT license](https://github.com/JetBrains-Research/viktor/blob/master/LICENSE), with JetBrains BioLabs as the copyright holder. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import com.github.tomtzook.gcmake.tasks.CmakeBuildTask | ||
import org.gradle.jvm.tasks.Jar | ||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget | ||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithSimulatorTests | ||
import org.jetbrains.kotlin.gradle.targets.native.tasks.artifact.KotlinNativeLinkArtifactTask | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink | ||
|
||
plugins { | ||
kotlin("multiplatform") version "2.0.0" | ||
id("io.github.tomtzook.gradle-cmake") version "1.2.2" | ||
} | ||
|
||
group = "com.martmists" | ||
version = "1.0-SNAPSHOT" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
cmake { | ||
targets { | ||
val simd by creating { | ||
cmakeLists = file("cmake/CMakeLists.txt") | ||
|
||
val linuxX64 by machines.customMachines.registering { | ||
toolchainFile = file("cmake/toolchains/linux-x64.cmake") | ||
} | ||
val linuxArm64 by machines.customMachines.registering { | ||
toolchainFile = file("cmake/toolchains/linux-arm64.cmake") | ||
} | ||
val mingwX64 by machines.customMachines.registering { | ||
toolchainFile = file("cmake/toolchains/mingw-x64.cmake") | ||
} | ||
val mingwArm64 by machines.customMachines.registering { | ||
toolchainFile = file("cmake/toolchains/mingw-arm64.cmake") | ||
} | ||
val macosX64 by machines.customMachines.registering { | ||
toolchainFile = file("cmake/toolchains/macos-x64.cmake") | ||
} | ||
val macosArm64 by machines.customMachines.registering { | ||
toolchainFile = file("cmake/toolchains/macos-arm64.cmake") | ||
} | ||
|
||
if (project.hasProperty("production")) { | ||
targetMachines.add(linuxX64) | ||
targetMachines.add(linuxArm64) | ||
targetMachines.add(mingwX64) | ||
// targetMachines.add(mingwArm64) | ||
targetMachines.add(macosX64) | ||
targetMachines.add(macosArm64) | ||
} else { | ||
targetMachines.add(linuxX64) | ||
} | ||
|
||
cmakeArgs = if (project.hasProperty("production")) { | ||
listOf("-DCMAKE_BUILD_TYPE=Release") | ||
} else { | ||
listOf("-DCMAKE_BUILD_TYPE=Debug") | ||
} | ||
} | ||
} | ||
} | ||
|
||
kotlin { | ||
jvm() | ||
|
||
val natives = if (project.hasProperty("production")) { | ||
listOf( | ||
linuxX64(), | ||
linuxArm64(), | ||
mingwX64(), | ||
// mingwArm64(), | ||
macosX64(), | ||
macosArm64(), | ||
) | ||
} else { | ||
when (System.getProperty("os.name")) { | ||
"Linux" -> listOf(linuxX64()) | ||
"Windows" -> listOf(mingwX64()) | ||
"Mac OS X" -> listOf(macosX64()) | ||
else -> error("Unsupported OS") | ||
} | ||
} | ||
|
||
for (native in natives) { | ||
native.apply { | ||
binaries { | ||
sharedLib { | ||
baseName = "ndarray_simd" | ||
} | ||
} | ||
|
||
compilerOptions { | ||
optIn = listOf( | ||
"kotlin.experimental.ExperimentalNativeApi", | ||
"kotlinx.cinterop.ExperimentalForeignApi", | ||
) | ||
} | ||
|
||
compilations.named("main") { | ||
val jni by cinterops.creating { | ||
val javaHome = File(System.getProperty("java.home")!!) | ||
defFile(project.projectDir.resolve("src/nativeMain/cinterops/jni.def")) | ||
includeDirs( | ||
javaHome.resolve("include"), | ||
javaHome.resolve("include/linux"), | ||
javaHome.resolve("include/darwin"), | ||
javaHome.resolve("include/win32"), | ||
) | ||
} | ||
|
||
val simd by cinterops.creating { | ||
defFile(project.projectDir.resolve("src/nativeMain/cinterops/simd.def")) | ||
includeDirs( | ||
project.projectDir.resolve("src/lib"), | ||
) | ||
|
||
extraOpts("-libraryPath", projectDir.resolve("build/cmake/simd/${target.name}/").absolutePath) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
tasks { | ||
val cmakeBuild by existing | ||
|
||
withType<KotlinNativeCompile> { | ||
dependsOn(cmakeBuild) | ||
} | ||
|
||
val jvmProcessResources by existing(Copy::class) { | ||
val binaryName = if (project.hasProperty("production")) { | ||
"releaseShared" | ||
} else { | ||
"debugShared" | ||
} | ||
|
||
for (native in kotlin.targets.withType<KotlinNativeTarget>()) { | ||
into("META-INF/natives/${native.targetName}") { | ||
from(named(native.binaries.getByName(binaryName).linkTaskName)) { | ||
exclude("**/*.h") | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
cmake_minimum_required(VERSION 3.30.0) | ||
project(simd) | ||
|
||
file(GLOB_RECURSE source_files ../src/lib/cpp/*.cpp) | ||
|
||
include_directories(../src/lib/public) | ||
|
||
add_library( | ||
simd STATIC ${source_files} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
set(CMAKE_SYSTEM_PROCESSOR aarch64) | ||
set("CMAKE_C_FLAGS" "-march=armv8-a --no-standard-libraries") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
set(CMAKE_SYSTEM_PROCESSOR x86_64) | ||
set("CMAKE_C_FLAGS" "-march=x86-64 --no-standard-libraries") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
set(CMAKE_SYSTEM_NAME Linux) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
set(CMAKE_SYSTEM_NAME Darwin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
set(CMAKE_SYSTEM_NAME Windows) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
set(CMAKE_C_FLAGS "-O2 -fPIC") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include("${CMAKE_CURRENT_LIST_DIR}/common.cmake") | ||
include("${CMAKE_CURRENT_LIST_DIR}/../platform/linux.cmake") | ||
include("${CMAKE_CURRENT_LIST_DIR}/../arch/arm64.cmake") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include("${CMAKE_CURRENT_LIST_DIR}/common.cmake") | ||
include("${CMAKE_CURRENT_LIST_DIR}/../platform/linux.cmake") | ||
include("${CMAKE_CURRENT_LIST_DIR}/../arch/x64.cmake") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include("${CMAKE_CURRENT_LIST_DIR}/common.cmake") | ||
include("${CMAKE_CURRENT_LIST_DIR}/../platform/macos.cmake") | ||
include("${CMAKE_CURRENT_LIST_DIR}/../arch/arm64.cmake") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include("${CMAKE_CURRENT_LIST_DIR}/common.cmake") | ||
include("${CMAKE_CURRENT_LIST_DIR}/../platform/macos.cmake") | ||
include("${CMAKE_CURRENT_LIST_DIR}/../arch/x64.cmake") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include("${CMAKE_CURRENT_LIST_DIR}/common.cmake") | ||
include("${CMAKE_CURRENT_LIST_DIR}/../platform/windows.cmake") | ||
include("${CMAKE_CURRENT_LIST_DIR}/../arch/arm64.cmake") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include("${CMAKE_CURRENT_LIST_DIR}/common.cmake") | ||
include("${CMAKE_CURRENT_LIST_DIR}/../platform/windows.cmake") | ||
include("${CMAKE_CURRENT_LIST_DIR}/../arch/x64.cmake") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
org.gradle.parallel=true | ||
|
||
kotlin.code.style=official | ||
kotlin.native.ignoreDisabledTargets=true | ||
kotlin.mpp.enableCInteropCommonization=true | ||
kotlin.mpp.enableCInteropCommonization.nowarn=true | ||
kotlin.native.binary.sourceInfoType=libbacktrace | ||
|
||
kotlin.native.cacheKind.linuxX64=none |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#Mon Jul 15 14:03:33 CEST 2024 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.