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

Issue 23 internal backend code refactor #27

Merged
merged 29 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a5604fa
remove dependence of MatMulAlgorithm on 'AbstractDeviceAlgorithm::exe…
Gleethos Dec 27, 2023
7668ee8
introduce test based on legacy/deprecated BroadSystemTest class.
Dec 29, 2023
3a95df1
put call preparation of BiElementwise operation into its own method
Dec 29, 2023
ae8fe56
improve testing
Dec 29, 2023
abd0bf2
improve testing
Dec 29, 2023
e1d11fe
delete redundant legacy test code (already covered by Spock tests)
Dec 29, 2023
e7d064e
delete redundant legacy test code (already covered by Spock tests)
Dec 29, 2023
017e1d2
ensure that execution call functions are first flattened before passe…
Dec 29, 2023
28edd53
improve CustomDeviceCleaner (fix leaking action memory)
Gleethos Feb 21, 2024
b19ca01
Merge remote-tracking branch 'refs/remotes/origin/issue-23-Internal_B…
Gleethos Feb 21, 2024
bc0b811
introduce error prone
May 13, 2024
7a7d2a6
remove redundant return flag in preparation for data based return types
May 13, 2024
93a506a
work towards making tensor construction more atomic by passing state …
May 14, 2024
8ee545c
simplify TensorConstructor
May 14, 2024
1c9a220
model the NDConfiguration of a deleted tensor using a dedicated null …
May 17, 2024
2a611fc
model the Data of a deleted tensor using a dedicated null object inst…
May 17, 2024
4b3fefa
Merge remote-tracking branch 'origin/issue-23-Internal_Backend_Code_R…
May 17, 2024
5424128
fix missing sync in CustomDeviceCleaner
May 17, 2024
8781234
fix unit test and compilation
Dec 9, 2024
90ea2e6
update gradle-wrapper.jar
Dec 10, 2024
2b8cba3
update dependencies
Dec 10, 2024
388b60a
make unit tests a bit more lenient
Dec 10, 2024
df8331b
try another kotlin runtime version
Dec 10, 2024
2dcbf23
add github workflow config
Gleethos Dec 10, 2024
44982a8
improve test logging
Gleethos Dec 10, 2024
756f1cf
fix Java 8 incompatibility due to usage of Optional::isEmpty
Gleethos Dec 10, 2024
8de78d3
fix code quality regressions
Gleethos Dec 10, 2024
d864d34
remove circleci CI config
Gleethos Dec 10, 2024
5654235
make code quality analyser happy
Gleethos Dec 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 0 additions & 61 deletions .circleci/config.yml

This file was deleted.

17 changes: 17 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Build And Test on All OSs
on: [push, pull_request]
jobs:
gradle:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
java: [1.8, 11, 17, 21]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- uses: eskatos/gradle-command-action@v1
with:
arguments: check --scan
62 changes: 50 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,20 @@ plugins {
id 'info.solidsoft.pitest' version '1.5.1'

// Kotlin tests:
id 'org.jetbrains.kotlin.jvm' version '1.3.31'
id 'org.jetbrains.kotlin.jvm' version '1.7.10'

// Public deployment :
id 'maven-publish'
id 'signing'
id('io.github.gradle-nexus.publish-plugin') version '1.1.0'

// For static analysis and null checking:
id "net.ltgt.errorprone" version "3.1.0"
}

// If current version >= 11 we can do static analysis:
boolean WE_CAN_DO_STATIC_ANALYSIS = JavaVersion.current().isJava11Compatible()
println "Static analysis enabled: $WE_CAN_DO_STATIC_ANALYSIS"


// This gives some more freedom for comments ( special characters... ).
Expand Down Expand Up @@ -135,18 +141,28 @@ repositories {
// Note: Visit the java-library gradle plugin documentation for more information about api vs implementation.
dependencies {

if ( WE_CAN_DO_STATIC_ANALYSIS ) {
errorprone "com.uber.nullaway:nullaway:0.10.25"
compileOnly "com.google.code.findbugs:jsr305:3.0.2"
errorprone "com.google.errorprone:error_prone_core:2.27.0"
}
else
errorprone "com.google.errorprone:error_prone_core:2.9.+"

implementation group: 'com.google.errorprone', name: 'error_prone_annotations', version: '2.27.0'
implementation group: 'org.jspecify', name: 'jspecify', version: '1.0.0'

// Core library dependencies :
implementation 'org.jocl:jocl:2.0.5' //-> Internal dependency!

// Logging :
implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.7'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '[1+, )'

// Test suite : Groovy, Spock (+ sl4j, + Spock-Reports)
//-----------------------------------------------------
// mandatory dependencies for using Spock
testImplementation 'org.codehaus.groovy:groovy:3.0.13'
testImplementation 'org.spockframework:spock-core:2.3-groovy-3.0'
testImplementation 'com.athaydes:spock-reports:2.3.2-groovy-3.0'
testImplementation 'org.spockframework:spock-core:2.3-groovy-4.0'
testImplementation 'com.athaydes:spock-reports:2.5.1-groovy-4.0'

//testImplementation group: 'org.apache.groovy', name: 'groovy', version: '4.0.6'
//testImplementation 'org.spockframework:spock-core:2.3-groovy-4.0'
Expand All @@ -156,14 +172,14 @@ dependencies {
testRuntimeOnly group: 'org.objenesis', name: 'objenesis', version: '3.2' // allows mocking of classes without default constructor (together with ByteBuddy or CGLIB)

// Kotlin tests:
testImplementation 'org.jetbrains.kotlin:kotlin-script-runtime:1.3.31' // first the runtime so that the tests compile
testImplementation 'org.jetbrains.kotlin:kotlin-script-runtime:1.7.10' // first the runtime so that the tests compile
testImplementation 'org.jetbrains.kotlin:kotlin-test' // Then some test dependencies to do assertions...
testImplementation 'org.assertj:assertj-core:3.23.1' // Same story here!
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.2'

testImplementation 'org.slf4j:slf4j-api:2.0.3' // LOGGING
testImplementation 'org.slf4j:slf4j-simple:2.0.3'
testImplementation 'org.slf4j:slf4j-api:2.0.12' // Logging in tests
testImplementation 'org.slf4j:slf4j-simple:2.0.12'
}

compileTestKotlin {
Expand All @@ -180,6 +196,9 @@ test {
// Spock-Reports configuration can be found in the test resources: src/test/resources/SpockConfig.Groovy

useJUnitPlatform() // ...otherwise spock tests will not be received by gradle...
testLogging {
exceptionFormat = 'full' // So we see spock power assert messages!
}

// Memory :
minHeapSize = "1g"
Expand All @@ -189,13 +208,32 @@ test {
maxParallelForks = 1//Math.floor(1+(Runtime.runtime.availableProcessors().intdiv(2) ?: 1)/2)
}

if ( WE_CAN_DO_STATIC_ANALYSIS ) {
tasks.withType(JavaCompile) {
// remove the if condition if you want to run NullAway on test code
if (!name.toLowerCase().contains("test")) {
options.errorprone {
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
option("NullAway:AnnotatedPackages", "")
// We disable the NonCanonicalType because non-canonical type declarations are used for convenience
check("NonCanonicalType", net.ltgt.gradle.errorprone.CheckSeverity.OFF)
}
} else {
options.errorprone {
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.WARN)
option("NullAway:AnnotatedPackages", "")
}
}
}
}


//----------------------------------------------------------------------------------------------------------------------
// 8. CONFIGURING TEST REPORTING :

jacoco {
toolVersion = "0.8.9"
reportsDir = file("docs/coverage")
toolVersion = "0.8.11"
reportsDirectory.set(file("docs/coverage"))
}

jacocoTestReport {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
18 changes: 14 additions & 4 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,10 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
Expand Down Expand Up @@ -143,12 +143,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -205,6 +209,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
15 changes: 9 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
23 changes: 7 additions & 16 deletions src/main/java/neureka/AbstractNda.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private void _setDataAndCountUsage( Data<V> newData ) {
if ( newData instanceof DeviceData )
( (DeviceData<?>) newData ).incrementUsageCount();

_data = newData; // This must be the only place where the data is set!!!
_data = ( newData != null ? newData : (Data<V>) Data.none()); // This must be the only place where the data is set!!!
}

protected <T> void _initDataArrayFrom( Filler<T> filler )
Expand Down Expand Up @@ -254,17 +254,13 @@ protected final void _allocateVirtual() {
*
* @return An {@link TensorConstructor} exposing a simple API for configuring a new {@link Tensor} instance.
*/
protected static TensorConstructor constructFor(AbstractNda<?, ?> nda, Device<?> targetDevice, NDConstructor ndConstructor )
protected static TensorConstructor constructFor( Device<?> targetDevice, NDConstructor ndConstructor )
{
return
new TensorConstructor(
targetDevice, ndConstructor,
new TensorConstructor.API() {
@Override public void setConf( NDConfiguration conf ) { nda.mut().setNDConf( conf ); }
@Override public void setData( Data o ) { nda._setData( o ); }
@Override public void setIsVirtual( boolean isVirtual ) { nda._setIsVirtual( isVirtual ); }
}
);
new TensorConstructor(
targetDevice, ndConstructor,
new TensorConstructor.Args()
);
}

/**
Expand Down Expand Up @@ -323,12 +319,7 @@ public boolean is( Class<?> typeClass ) {
protected void _setNDConf( NDConfiguration ndConfiguration )
{
_guardSet( "ND-Configuration" );
if ( _NDConf != null && ndConfiguration != null ) {
int s1 = Arrays.stream( _NDConf.shape() ).map( Math::abs ).reduce( 1, ( a, b ) -> a * b );
int s2 = Arrays.stream( ndConfiguration.shape() ).map( Math::abs ).reduce( 1, ( a, b ) -> a * b );
assert s1 == s2;
}
_NDConf = ndConfiguration;
_NDConf = ( ndConfiguration != null ? ndConfiguration : NDConfiguration.none() );
}

}
11 changes: 11 additions & 0 deletions src/main/java/neureka/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
*/
public interface Data<V>
{
/**
* This is a static factory method which returns a {@link Data} object
* which does not contain any data. It is a sort of no-operation null object
* which can be used to represent the absence of data.
* A deleted tensor will typically have a {@link Data} object which does not contain any data.
*
* @return A {@link Data} object which does not contain any data.
*/
static Data<Void> none() { return NoOpData.INSTANCE; }


static <V> Data<V> of( Class<V> type, V... data ) { return CPU.get().allocate( type, data ); }

static Data<Float> of( float... items ) { return CPU.get().allocate( Float.class, items ); }
Expand Down
Loading
Loading