Skip to content

Commit

Permalink
feat!: [Java] fix up #802: SupportedDevicesを移動
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Feb 9, 2025
1 parent 38e5dbe commit d4184f2
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package jp.hiroshiba.voicevoxcore;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import jakarta.annotation.Nonnull;
import jp.hiroshiba.voicevoxcore.internal.Dll;

Expand All @@ -27,63 +25,4 @@ public static String getVersion() {
// FIXME: dead code
@Nonnull
private static native String rsGetSupportedDevicesJson();

// FIXME: `Onnxruntime`に移すか、独立させる
/**
* ONNX Runtime利用可能なデバイスの情報。
*
* <p>あくまでONNX Runtimeが対応しているデバイスの情報であることに注意。GPUが使える環境ではなかったとしても {@link #cuda} や {@link #dml} は
* {@code true} を示しうる。
*
* <p>現在この型はGSONに対応しているが、将来的には <a href="https://github.com/VOICEVOX/voicevox_core/issues/984"
* target="_blank">Jacksonに切り替わる予定</a> 。
*
* <p>{@code Gson#fromJson} でJSONから変換することはできない。その試みは {@link UnsupportedOperationException} となる。
*/
public static class SupportedDevices {
/**
* CPUが利用可能。
*
* <p>常に <code>true</code> 。
*/
@SerializedName("cpu")
@Expose
@Nonnull
public final boolean cpu;

/**
* CUDAが利用可能。
*
* <p>ONNX Runtimeの <a href=
* "https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html"
* target="_blank">CUDAExecutionProvider</a>に対応する。 必要な環境についてはそちらを参照。
*/
@SerializedName("cuda")
@Expose
@Nonnull
public final boolean cuda;

/**
* DirectMLが利用可能。
*
* <p>ONNX Runtimeの <a href=
* "https://onnxruntime.ai/docs/execution-providers/DirectML-ExecutionProvider.html"
* target="_blank">DmlExecutionProvider</a>に対応する。 必要な環境についてはそちらを参照。
*/
@SerializedName("dml")
@Expose
@Nonnull
public final boolean dml;

private SupportedDevices() {
throw new UnsupportedOperationException("You cannot deserialize `SupportedDevices`");
}

/** accessed only via JNI */
private SupportedDevices(boolean cpu, boolean cuda, boolean dml) {
this.cpu = cpu;
this.cuda = cuda;
this.dml = dml;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package jp.hiroshiba.voicevoxcore;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import jakarta.annotation.Nonnull;

/**
* ONNX Runtime利用可能なデバイスの情報。
*
* <p>あくまでONNX Runtimeが対応しているデバイスの情報であることに注意。GPUが使える環境ではなかったとしても {@link #cuda} や {@link #dml} は
* {@code true} を示しうる。
*
* <p>現在この型はGSONに対応しているが、将来的には <a href="https://github.com/VOICEVOX/voicevox_core/issues/984"
* target="_blank">Jacksonに切り替わる予定</a> 。
*
* <p>{@code Gson#fromJson} でJSONから変換することはできない。その試みは {@link UnsupportedOperationException} となる。
*/
public class SupportedDevices {
/**
* CPUが利用可能。
*
* <p>常に <code>true</code> 。
*/
@SerializedName("cpu")
@Expose
@Nonnull
public final boolean cpu;

/**
* CUDAが利用可能。
*
* <p>ONNX Runtimeの <a href=
* "https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html"
* target="_blank">CUDAExecutionProvider</a>に対応する。 必要な環境についてはそちらを参照。
*/
@SerializedName("cuda")
@Expose
@Nonnull
public final boolean cuda;

/**
* DirectMLが利用可能。
*
* <p>ONNX Runtimeの <a href=
* "https://onnxruntime.ai/docs/execution-providers/DirectML-ExecutionProvider.html"
* target="_blank">DmlExecutionProvider</a>に対応する。 必要な環境についてはそちらを参照。
*/
@SerializedName("dml")
@Expose
@Nonnull
public final boolean dml;

private SupportedDevices() {
throw new UnsupportedOperationException("You cannot deserialize `SupportedDevices`");
}

/** accessed only via JNI */
private SupportedDevices(boolean cpu, boolean cuda, boolean dml) {
this.cpu = cpu;
this.cuda = cuda;
this.dml = dml;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package jp.hiroshiba.voicevoxcore.blocking;

import static jp.hiroshiba.voicevoxcore.GlobalInfo.SupportedDevices;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import java.util.Optional;
import jp.hiroshiba.voicevoxcore.SupportedDevices;
import jp.hiroshiba.voicevoxcore.internal.Dll;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void checkVersion() {
// TODO: 別の場所に移す
@Test
void checkSupportedDevices() {
GlobalInfo.SupportedDevices supportedDevices = loadOnnxruntime().supportedDevices();
SupportedDevices supportedDevices = loadOnnxruntime().supportedDevices();

assertNotNull(supportedDevices);
assertTrue(supportedDevices.cpu);
Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core_java_api/src/onnxruntime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Onnxruntime_rs
});

let devices = env.new_object(
object!("GlobalInfo$SupportedDevices"),
object!("SupportedDevices"),
"(ZZZ)V",
&[devices.cpu.into(), devices.cuda.into(), devices.dml.into()],
)?;
Expand Down

0 comments on commit d4184f2

Please sign in to comment.