deeplearning4j/deeplearning4j · error · IllegalArgumentException

Unknown datatype:

Error message

Unknown datatype: 

What it means

BaseCudaDataBuffer's init/create path builds the host pointer and indexer based on the buffer's DataType; any DataType outside the handled cases (DOUBLE, FLOAT, HALF, INT, LONG, SHORT, BYTE, UBYTE, BFLOAT16, UTF8 as implemented in the if/else chain) falls into the final else and throws. It means the CUDA backend cannot map this buffer's datatype to a JavaCPP pointer/indexer pair. This is an internal datatype-dispatch guard, so it usually surfaces from an unsupported or uninitialized DataType rather than user data.

Solutions

  1. Verify the DataType is one the CUDA backend supports (DOUBLE, FLOAT, HALF, INT, LONG, SHORT, BYTE, UBYTE, BFLOAT16, UTF8).
  2. Convert the data to a supported DataType before creating the buffer (e.g. Nd4j.create(..., DataType.FLOAT)).
  3. Align nd4j-core and nd4j-cuda backend versions in the dependency tree so all DataType enum values are supported.
  4. If COMPRESSED data is involved, decompress (Nd4j.getExecutioner().decompress()) before creating the CUDA buffer.

Example fix

// before
INDArray a = Nd4j.create(data, new int[]{rows, cols}, DataType.COMPRESSED);
// after
INDArray a = Nd4j.create(data, new int[]{rows, cols}, DataType.FLOAT);
Defensive patterns

Strategy: validation

Validate before calling

Set<DataType> SUPPORTED = EnumSet.of(DataType.DOUBLE, DataType.FLOAT, DataType.HALF, DataType.INT, DataType.LONG, DataType.SHORT, DataType.BYTE, DataType.UBYTE, DataType.BFLOAT16, DataType.UTF8);
if (!SUPPORTED.contains(buffer.dataType())) throw new IllegalStateException("Unsupported CUDA datatype: " + buffer.dataType());

Type guard

static boolean isCudaSupportedType(DataType t) {
    return t != null && EnumSet.of(DataType.DOUBLE, DataType.FLOAT, DataType.HALF, DataType.INT,
        DataType.LONG, DataType.SHORT, DataType.BYTE, DataType.UBYTE, DataType.BFLOAT16, DataType.UTF8).contains(t);
}

Try / catch

try {
    DataBuffer buf = Nd4j.createBuffer(data, dataType);
} catch (IllegalArgumentException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Unknown datatype")) {
        buf = Nd4j.createBuffer(data, DataType.FLOAT); // fallback to supported dtype
    } else throw e;
}

Prevention

When it happens

Trigger: Constructing a CUDA-backed DataBuffer with a DataType the if/else chain does not handle, e.g. COMPRESSED, UNKNOWN, or a datatype whose assignment path was skipped; calling the init method when dataType() returns null or a newly added enum value from an inconsistent backend version.

Common situations: Mixing nd4j versions where a newer DataType enum value is stored in serialized buffers but the CUDA backend was built without support; creating buffers via a generic factory with an accidentally unset datatype; using compressed buffers with unsupported CUDA operations.

Related errors


AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07). Data as JSON: /api/errors/7c39685872bcc221. Report an issue: GitHub.

Appendix: source

Thrown at nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/buffer/BaseCudaDataBuffer.java:1798

            pointer = new PagedPointer(cptr, length).asLongPointer();
            setIndexer(LongIndexer.create((LongPointer) pointer));
        } else if (t == DataType.BFLOAT16) {
            pointer = new PagedPointer(cptr, length).asShortPointer();
            setIndexer(Bfloat16Indexer.create((ShortPointer) pointer));
        } else if (t == DataType.HALF) {
            pointer = new PagedPointer(cptr, length).asShortPointer();
            setIndexer(HalfIndexer.create((ShortPointer) pointer));
        } else if (t == DataType.FLOAT) {
            pointer = new PagedPointer(cptr, length).asFloatPointer();
            setIndexer(FloatIndexer.create((FloatPointer) pointer));
        } else if (t == DataType.DOUBLE) {
            pointer = new PagedPointer(cptr, length).asDoublePointer();
            setIndexer(DoubleIndexer.create((DoublePointer) pointer));
        } else if (t == DataType.UTF8) {
            pointer = new PagedPointer(cptr, length()).asBytePointer();
            setIndexer(ByteIndexer.create((BytePointer) pointer));
        } else
            throw new IllegalArgumentException("Unknown datatype: " + dataType());
    }

    @Override
    public DataBuffer reallocate(long length) {
        val oldHostPointer = this.ptrDataBuffer.primaryBuffer();
        val oldDevicePointer = this.ptrDataBuffer.specialBuffer();

        if (isAttached()) {
            val capacity = length * getElementSize();

            if (oldDevicePointer != null && oldDevicePointer.address() != 0) {
                val nPtr = getParentWorkspace().alloc(capacity, MemoryKind.DEVICE, dataType(), false);
                NativeOpsHolder.getInstance().getDeviceNativeOps().memcpySync(nPtr, oldDevicePointer, length * getElementSize(), 3, null);
                this.ptrDataBuffer.setPrimaryBuffer(nPtr, length);

                allocationPoint.tickDeviceRead();
            }

View on GitHub (pinned to 4c22ac5fe4)