Skip to content

Commit

Permalink
Merge pull request #6 from Holt666/master
Browse files Browse the repository at this point in the history
optimize performance
  • Loading branch information
LucasMLK authored Apr 14, 2023
2 parents 5849e25 + 2887107 commit 1496fb5
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: maven ci
name: maven-build

on:
push:
Expand All @@ -19,8 +19,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: maven-publish
on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- name: Set up Java for publishing to Maven Central Repository
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
- name: Publish to the Maven Central Repository
run: mvn --batch-mode deploy
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
- name: Set up Java for publishing to GitHub Packages
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Publish to GitHub Packages
run: mvn --batch-mode deploy
env:
GITHUB_TOKEN: ${{ secrets.G_TOKEN }}
19 changes: 5 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,19 @@ cd xdagj-native-randomx
git submodule init
git submodule update
```
### 2.2 compile randomx lib

#### 2.2.1 change cmake setting
### 2.2 compile randomx lib

#### 2.2.1 compile randomx share lib
```
cd randomx
vim CMakeLists.txt
```
modify CMakeList.txt in randomx folder.
change "add_library(randomx ${randomx_sources})" at line 178 to
"add_library(randomx SHARED ${randomx_sources})"

#### 2.2.2 compile c++ lib
```
mkdir build && cd build
cmake -DARCH=native ..
cmake .. -DARCH=native -DBUILD_SHARED_LIBS=ON -DCMAKE_C_FLAGS="-fPIC"
make
cp -i librandomx.dylib ../../src/main/resources
overwrite ../../src/main/resources/librandomx.dylib? (y/n [n]) y
```

#### 2.2.3 compile java lib
#### 2.2.2 compile java lib

```
cd ../../
Expand All @@ -71,7 +62,7 @@ mvn package
<dependency>
<groupId>io.xdag</groupId>
<artifactId>xdagj-native-randomx</artifactId>
<version>0.1.5</version>
<version>0.1.6</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.xdag</groupId>
<artifactId>xdagj-native-randomx</artifactId>
<version>0.1.5</version>
<version>0.1.6</version>

<name>xdagj-native-randomx</name>
<description>A Java RandomX Library For XDAGJ</description>
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/io/xdag/crypto/randomx/RandomXWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public void init(byte[] key) {
* @return RandomX_VM an Object representing the resulting VM
*/
public RandomXVM createVM() {
if (flags.contains(RandomXFlag.JIT)){
flagsValue = RandomXFlag.JIT.getValue();
}
RandomXVM vm = new RandomXVM(RandomXJNA.INSTANCE.randomx_create_vm(flagsValue, cache, dataset), this);
vms.add(vm);
return vm;
Expand All @@ -83,7 +86,9 @@ public RandomXVM createVM() {
private void setCache(byte[] key) {
if(this.memory != null && Arrays.equals(key, this.memory.getByteArray(0, keySize)))
return;

if (flags.contains(RandomXFlag.JIT)){
flagsValue = RandomXFlag.JIT.getValue();
}
PointerByReference newCache = RandomXJNA.INSTANCE.randomx_alloc_cache(flagsValue);

this.memory = new Memory(key.length);
Expand Down Expand Up @@ -116,6 +121,8 @@ private void setDataset(byte[] key) {
//Allocate memory for dataset
if(flags.contains(RandomXFlag.LARGE_PAGES)) {
newDataset = RandomXJNA.INSTANCE.randomx_alloc_dataset(RandomXFlag.LARGE_PAGES.getValue());
} else if (flags.contains(RandomXFlag.JIT)){
newDataset = RandomXJNA.INSTANCE.randomx_alloc_dataset(RandomXFlag.JIT.getValue());
} else {
newDataset = RandomXJNA.INSTANCE.randomx_alloc_dataset(0);
}
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/io/xdag/crypto/randomx/RandomXJNAPerfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
Expand Down Expand Up @@ -74,8 +73,7 @@ public byte[] testHash() {
return randomxVm.getHash(buffer);
}

@Test
public void main() throws RunnerException {
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(RandomXJNAPerfTest.class.getSimpleName())
.build();
Expand Down

0 comments on commit 1496fb5

Please sign in to comment.