Skip to content
Merged
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
Expand Up @@ -17,6 +17,8 @@

import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

/**
Expand All @@ -43,7 +45,10 @@ private static CuVSProvider loadProvider() {
}

static CuVSProvider builtinProvider() {
if (Runtime.version().feature() > 21 && isLinuxAmd64()) {
var supportedJavaRuntime = Runtime.version().feature() > 21;
var supportedOs = System.getProperty("os.name").startsWith("Linux");
var supportedArchitecture = System.getProperty("os.arch").equals("amd64");
if (supportedJavaRuntime && supportedOs && supportedArchitecture) {
try {
var cls = Class.forName("com.nvidia.cuvs.spi.JDKProvider");
var ctr = MethodHandles.lookup().findConstructor(cls, MethodType.methodType(void.class));
Expand All @@ -52,16 +57,18 @@ static CuVSProvider builtinProvider() {
throw new AssertionError(e);
}
}
return new UnsupportedProvider();
}
List<String> unsupportedReasons = new ArrayList<>();
if (!supportedJavaRuntime) {
unsupportedReasons.add("cuvs-java requires Java Runtime version 22 or greater");
}
if (!supportedOs) {
unsupportedReasons.add("cuvs-java supports only Linux");
}
if (!supportedArchitecture) {
unsupportedReasons.add("cuvs-java supports only x86");
}

/**
* Returns true iff the architecture is x64 (amd64) and the OS Linux
* (the * OS we currently support for the native lib).
*/
static boolean isLinuxAmd64() {
String name = System.getProperty("os.name");
return (name.startsWith("Linux")) && System.getProperty("os.arch").equals("amd64");
return new UnsupportedProvider(String.join("; ", unsupportedReasons));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,57 @@
*/
final class UnsupportedProvider implements CuVSProvider {

private final String reasons;

public UnsupportedProvider(String reasons) {
this.reasons = reasons;
}

@Override
public CuVSResources newCuVSResources(Path tempDirectory) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException(reasons);
}

@Override
public BruteForceIndex.Builder newBruteForceIndexBuilder(CuVSResources cuVSResources) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException(reasons);
}

@Override
public CagraIndex.Builder newCagraIndexBuilder(CuVSResources cuVSResources) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException(reasons);
}

@Override
public HnswIndex.Builder newHnswIndexBuilder(CuVSResources cuVSResources) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException(reasons);
}

@Override
public TieredIndex.Builder newTieredIndexBuilder(CuVSResources cuVSResources) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException(reasons);
}

@Override
public CagraIndex mergeCagraIndexes(CagraIndex[] indexes) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException(reasons);
}

@Override
public CuVSMatrix.Builder<CuVSHostMatrix> newHostMatrixBuilder(
long size, long dimensions, CuVSMatrix.DataType dataType) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException(reasons);
}

@Override
public CuVSMatrix.Builder<CuVSDeviceMatrix> newDeviceMatrixBuilder(
CuVSResources cuVSResources, long size, long dimensions, CuVSMatrix.DataType dataType) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException(reasons);
}

@Override
public GPUInfoProvider gpuInfoProvider() {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException(reasons);
}

@Override
Expand All @@ -79,26 +85,26 @@ public CuVSMatrix.Builder<CuVSDeviceMatrix> newDeviceMatrixBuilder(
int rowStride,
int columnStride,
CuVSMatrix.DataType dataType) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException(reasons);
}

@Override
public MethodHandle newNativeMatrixBuilder() {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException(reasons);
}

@Override
public CuVSMatrix newMatrixFromArray(float[][] vectors) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException(reasons);
}

@Override
public CuVSMatrix newMatrixFromArray(int[][] vectors) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException(reasons);
}

@Override
public CuVSMatrix newMatrixFromArray(byte[][] vectors) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException(reasons);
}
}