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

fix!: [Java] fix up #802: SupportedDevicesを移動 #991

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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