Skip to content

Commit

Permalink
Merge pull request #198 from Kotlin/V0.3.0
Browse files Browse the repository at this point in the history
Fix build and js tests
  • Loading branch information
devcrocod authored Feb 6, 2024
2 parents 661468c + b147bec commit 79dedd1
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 63 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ repositories {
}
dependencies {
implementation "org.jetbrains.kotlinx:multik-core:0.2.2"
implementation "org.jetbrains.kotlinx:multik-default:0.2.2"
implementation "org.jetbrains.kotlinx:multik-core:0.2.3"
implementation "org.jetbrains.kotlinx:multik-default:0.2.3"
}
```

Expand All @@ -40,8 +40,8 @@ repositories {
}

dependencies {
implementation("org.jetbrains.kotlinx:multik-core:0.2.2")
implementation("org.jetbrains.kotlinx:multik-default:0.2.2")
implementation("org.jetbrains.kotlinx:multik-core:0.2.3")
implementation("org.jetbrains.kotlinx:multik-default:0.2.3")
}
```

Expand All @@ -52,7 +52,7 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:multik-core:0.2.2")
implementation("org.jetbrains.kotlinx:multik-core:0.2.3")
}
}
}
Expand All @@ -66,7 +66,7 @@ kotlin {
sourceSets {
val jvmName by getting {
dependencies {
implementation("org.jetbrains.kotlinx:multik-core-jvm:0.2.2")
implementation("org.jetbrains.kotlinx:multik-core-jvm:0.2.3")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kotlin.code.style=official
multik_version=0.2.2
multik_version=0.2.3

# Kotlin
systemProp.kotlin_version=1.9.22
Expand Down
54 changes: 26 additions & 28 deletions gradle/multik_jni-cmake.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@

def cmake_path = "${rootDir}/multik-openblas/multik_jni"
def path_to_build = file("${buildDir}/cmake-build")
def path_to_build = layout.buildDirectory.dir("cmake-build").get().asFile.absolutePath

def String getTargetOSAndArch() {
String getTargetOSAndArch() {
String hostOs = System.getProperty('os.name').toLowerCase()
String hostArch = System.getProperty('os.arch').toLowerCase()
if (hostOs == "mac os x" && hostArch == "x86_64")
return 'macosX64'
else if(hostOs == "mac os x" && hostArch == "aarch64")
else if (hostOs == "mac os x" && hostArch == "aarch64")
return 'macosArm64'
else if(hostOs == "linux")
else if (hostOs == "linux")
return 'linuxX64'
else if(hostOs.startsWith("windows"))
else if (hostOs.startsWith("windows"))
return 'mingwX64'
else
throw GradleException("""
Expand All @@ -34,43 +33,42 @@ static boolean isWindows() {
return System.getProperty('os.name').toLowerCase().contains('windows')
}

task createBuildDir() {
mkdir(project.buildDir)
mkdir(file("${project.buildDir}/cmake-build"))
tasks.register('createBuildDir') {
doLast {
mkdir(layout.buildDirectory.get().asFile)
mkdir(layout.buildDirectory.dir("cmake-build").get().asFile)
}
}

task config_cmake(dependsOn: createBuildDir) {
def type_build = "-DCMAKE_BUILD_TYPE=Release"
def gen = isWindows() ? "CodeBlocks - MinGW Makefiles" : "CodeBlocks - Unix Makefiles"
def c_compiler = "-DCMAKE_C_COMPILER=$cmake_c_compiler"
def cxx_compiler = "-DCMAKE_CXX_COMPILER=$cmake_cxx_compiler"
def path_to_gcc_lib = "-DGCC_LIB_PATH=$lib_gcc_path"
tasks.register('config_cmake') {
dependsOn createBuildDir
String gen = isWindows() ? "-G CodeBlocks - MinGW Makefiles" : ""
doLast {
exec {
commandLine("cmake",
type_build,
c_compiler,
cxx_compiler,
path_to_gcc_lib,
commandLine "cmake",
"-DCMAKE_BUILD_TYPE=Release",
"-DCMAKE_C_COMPILER=$cmake_c_compiler",
"-DCMAKE_CXX_COMPILER=$cmake_cxx_compiler",
"-DGCC_LIB_PATH=$lib_gcc_path",
"-DTARGET_OS=$targetOS",
"-G", gen,
gen,
"-S", cmake_path,
"-B", path_to_build,
)
"-B", path_to_build
}
}
}


task build_cmake(dependsOn: config_cmake) {
tasks.register('build_cmake') {
dependsOn config_cmake
String jProc = Runtime.getRuntime().availableProcessors().toString()
doLast {
exec {
commandLine("cmake", "--build", path_to_build, "--target", "multik_jni-$targetOS", "--", "-j", "12")
commandLine("cmake", "--build", path_to_build, "--target", "multik_jni-$targetOS", "--", "-j", "$jProc")
}
copy {
from("${project.buildDir}/cmake-build")
from(path_to_build)
include("*.dylib", "*.so", "*.dll")
into("${project.buildDir}/libs")
into(layout.buildDirectory.dir("libs").get().asFile)
}
}
}
24 changes: 20 additions & 4 deletions multik-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,29 @@ kotlin {
iosSimulatorArm64()
iosX64()
wasmJs {
browser()
nodejs()
browser {
testTask {
enabled = false
}
}
nodejs {
testTask {
enabled = false
}
}
d8()
}
js(IR) {
browser()
nodejs()
browser {
testTask {
useMocha()
}
}
nodejs {
testTask {
useMocha()
}
}
}

sourceSets {
Expand Down
24 changes: 20 additions & 4 deletions multik-default/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,29 @@ kotlin {
}
}
wasmJs {
browser()
nodejs()
browser {
testTask {
enabled = false
}
}
nodejs {
testTask {
enabled = false
}
}
d8()
}
js(IR) {
browser()
nodejs()
browser {
testTask {
useMocha()
}
}
nodejs {
testTask {
useMocha()
}
}
}

val hostOs = System.getProperty("os.name")
Expand Down
45 changes: 26 additions & 19 deletions multik-openblas/multik_jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ cmake_minimum_required(VERSION 3.16)
project(multik_jni)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(PLATFORM ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR})

if (NOT DEFINED TARGET_OS)
set(TARGET_OS ${PLATFORM})
endif ()

#### PARAMETERS FOR OPENBLAS ####
set(OPENBLAS_VERSION 0.3.23)
set(OPENBLAS_VERSION 0.3.26)

if (${TARGET_OS} STREQUAL "mingwX64" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(URL_OPENBLAS "https://github.com/xianyi/OpenBLAS/releases/download/v${OPENBLAS_VERSION}/OpenBLAS-${OPENBLAS_VERSION}-x64.zip")
set(URL_OPENBLAS "https://github.com/OpenMathLib/OpenBLAS/releases/download/v${OPENBLAS_VERSION}/OpenBLAS-${OPENBLAS_VERSION}-x64.zip")
else ()
# set(URL_OPENBLAS "https://github.com/xianyi/OpenBLAS/archive/refs/heads/develop.zip") # TODO(switch to stable version)
set(URL_OPENBLAS "https://github.com/xianyi/OpenBLAS/archive/v${OPENBLAS_VERSION}.zip")
set(URL_OPENBLAS "https://github.com/OpenMathLib/OpenBLAS/archive/v${OPENBLAS_VERSION}.zip")
endif ()

set(CC ${CMAKE_C_COMPILER})
Expand All @@ -27,26 +28,26 @@ set(USE_OPENMP 0)
set(NUM_THREADS 64)
set(DYNAMIC_LIST )

if (${TARGET_OS} MATCHES "androidArm64")
if(${TARGET_OS} STREQUAL "androidArm64")
set(suffix androidArm64)
set(CC aarch64-linux-android-gcc)
set(FC aarch64-linux-android-gfortran)
set(CROSS_SUFFIX aarch64-linux-android-)
set(NO_AVX512 1)
elseif (${TARGET_OS} MATCHES "linuxX64")
set(DYNAMIC_LIST ARM8)
elseif(${TARGET_OS} STREQUAL "linuxX64")
set(suffix linuxX64)
set(FC "gfortran -m64")
set(FEXTRALIB -lgfortran)
set(NO_AVX512 0)
set(DYNAMIC_ARCH 1)
elseif (${TARGET_OS} MATCHES "macosArm64" OR ${PLATFORM} MATCHES "Darwin-arm64")
elseif (${TARGET_OS} STREQUAL "macosArm64" OR ${PLATFORM} MATCHES "Darwin-arm64")
set(suffix macosArm64)
set(FC "gfortran")
set(FEXTRALIB "-lgfortran")
set(NO_AVX512 1)
# set(DYNAMIC_ARCH 1)
set(DYNAMIC_LIST "ARMV8 CORTEXA55 CORTEXA72 CORTEXA78") # TODO(XCODE workaround)
elseif (${TARGET_OS} MATCHES "macosX64" OR ${PLATFORM} MATCHES "Darwin-x86_64")
set(DYNAMIC_ARCH 1)
elseif(${TARGET_OS} STREQUAL "macosX64" OR ${PLATFORM} MATCHES "Darwin-x86_64")
set(suffix macosX64)
set(FC "gfortran")
set(FEXTRALIB "-lgfortran")
Expand All @@ -59,7 +60,7 @@ elseif (${TARGET_OS} MATCHES "mingwX64")
set(NO_AVX512 1)
set(DYNAMIC_ARCH 1)
else()
message(SEND_ERROR "Platform ${PLATFORM} is not supported")
message(WARNING "Platform ${PLATFORM} is not supported")
return()
endif ()
########################
Expand All @@ -74,6 +75,7 @@ if (${TARGET_OS} STREQUAL "mingwX64")
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
# DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
#### INCLUDE OPENBLAS ####
ExternalProject_Get_property(openblas SOURCE_DIR)
Expand Down Expand Up @@ -101,6 +103,7 @@ else ()
DYNAMIC_LIST=${DYNAMIC_LIST}
NUM_THREADS=${NUM_THREADS}
INSTALL_COMMAND ${MAKE_EXE} -C <SOURCE_DIR> install PREFIX=<INSTALL_DIR> CC=${CC}
# DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
#### INCLUDE OPENBLAS ####
ExternalProject_Get_property(openblas INSTALL_DIR)
Expand Down Expand Up @@ -129,8 +132,8 @@ set(SRC_FILES_FOR_STATIC
########################

### FIND GFORTRAN AND QUADMATH LIBRARIES ###
if (${GCC_LIB_PATH})
message("Path to gcc libs does not defined")
if (NOT DEFINED GCC_LIB_PATH)
message(WARNING "Path to gcc libs is not defined")
endif ()
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(LIB_GFORTRAN -static-libgfortran)
Expand Down Expand Up @@ -165,16 +168,20 @@ endif ()
set(LIB_NAME multik_jni-${suffix})

add_library(${LIB_NAME} SHARED ${SRC_FILES_FOR_SHARED})
target_compile_options(${LIB_NAME} PRIVATE -std=c++14
-fPIC
-O3
-fno-exceptions
-ffast-math)
target_compile_features(${LIB_NAME} PRIVATE cxx_std_14)
target_compile_options(${LIB_NAME} PRIVATE
-fPIC
-O3
-fno-exceptions
-ffast-math
-flto
-funroll-loops
)
target_include_directories(${LIB_NAME} PUBLIC ${JNI_INCLUDE_DIRS})
target_link_libraries(${LIB_NAME} optimized
${STATIC_OPENBLAS}
${LIB_GFORTRAN}
# ${LIB_QUADMATH}
${LIB_GCC}
)
)
add_dependencies(${LIB_NAME} openblas)
1 change: 1 addition & 0 deletions multik-openblas/multik_jni/src/main/cpp/jni_Linalg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "jni_JniLinAlg.h"
#include "mk_linalg.h"
#include <ComplexDouble.h>
#include <cstdint>

/*
* Class: org_jetbrains_kotlinx_multik_openblas_linalg_JniLinAlg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class NativeLinAlgTest {
)

val actual = NativeLinAlg.dot(matrix1, matrix2)
assertEquals(expected, actual)
assertComplexFloatingNDArray(expected, actual, 1e-4f)
}

@Test
Expand Down

0 comments on commit 79dedd1

Please sign in to comment.