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
2 changes: 1 addition & 1 deletion get_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ MKL=mkl
ONNXRUNTIME=onnxruntime

######################################################################################## DLPACK
DLPACK_VERSION="v0.3"
DLPACK_VERSION="v0.4"
if [[ $WITH_DLPACK != 0 ]]; then
[[ $FORCE == 1 ]] && rm -rf $DLPACK

Expand Down
4 changes: 2 additions & 2 deletions src/backends/onnxruntime.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ RAI_Tensor *RAI_TensorCreateFromOrtValue(OrtValue *v, size_t batch_offset, long

ret = RAI_TensorNew();

DLContext ctx = (DLContext){.device_type = kDLCPU, .device_id = 0};
DLDevice device = (DLDevice){.device_type = kDLCPU, .device_id = 0};

OrtTensorTypeAndShapeInfo *info;
status = ort->GetTensorTypeAndShape(v, &info);
Expand Down Expand Up @@ -243,7 +243,7 @@ RAI_Tensor *RAI_TensorCreateFromOrtValue(OrtValue *v, size_t batch_offset, long
// TODO: use manager_ctx to ensure ORT tensor doesn't get deallocated
// This applies to outputs

ret->tensor = (DLManagedTensor){.dl_tensor = (DLTensor){.ctx = ctx,
ret->tensor = (DLManagedTensor){.dl_tensor = (DLTensor){.device = device,
#ifdef RAI_COPY_RUN_OUTPUT
.data = data,
#else
Expand Down
4 changes: 2 additions & 2 deletions src/backends/tensorflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ RAI_Tensor *RAI_TensorCreateFromTFTensor(TF_Tensor *tensor, size_t batch_offset,
long long batch_size) {
RAI_Tensor *ret = RAI_TensorNew();

DLContext ctx = (DLContext){.device_type = kDLCPU, .device_id = 0};
DLDevice device = (DLDevice){.device_type = kDLCPU, .device_id = 0};

const size_t ndims = TF_NumDims(tensor);

Expand Down Expand Up @@ -129,7 +129,7 @@ RAI_Tensor *RAI_TensorCreateFromTFTensor(TF_Tensor *tensor, size_t batch_offset,
// This applies to outputs

ret->tensor = (DLManagedTensor){
.dl_tensor = (DLTensor){.ctx = ctx,
.dl_tensor = (DLTensor){.device = device,
#ifdef RAI_COPY_RUN_OUTPUT
.data = data,
#else
Expand Down
19 changes: 7 additions & 12 deletions src/libtflite_c/tflite_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,11 @@ static DLDataType getDLDataType(const TfLiteTensor *tensor) {
return dtype;
}

static DLContext getDLContext(const TfLiteTensor *tensor, const int64_t &device_id) {
DLContext ctx;
ctx.device_id = device_id;
// if (tensor->.is_cuda()) {
// ctx.device_type = DLDeviceType::kDLGPU;
// } else {
// ctx.device_type = DLDeviceType::kDLCPU;
// }
ctx.device_type = DLDeviceType::kDLCPU;
return ctx;
static DLDevice getDLDevice(const TfLiteTensor *tensor, const int64_t &device_id) {
DLDevice device;
device.device_id = device_id;
device.device_type = DLDeviceType::kDLCPU;
return device;
}

#if 0
Expand Down Expand Up @@ -139,10 +134,10 @@ DLManagedTensor *toManagedDLPack(std::shared_ptr<tflite::Interpreter> interprete
DLDataType dtype = getDLDataType(tensor);

int64_t device_id = 0;
DLContext ctx = getDLContext(tensor, device_id);
DLDevice device = getDLDevice(tensor, device_id);

DLTensor dl_tensor = (DLTensor){.data = new uint8_t[tensor->bytes],
.ctx = ctx,
.device = device,
.ndim = output_dims->size,
.dtype = dtype,
.shape = new int64_t[output_dims->size],
Expand Down
16 changes: 8 additions & 8 deletions src/libtorch_c/torch_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ static DLDataType getDLDataType(const at::Tensor &t) {
return dtype;
}

static DLContext getDLContext(const at::Tensor &tensor, const int64_t &device_id) {
DLContext ctx;
ctx.device_id = device_id;
static DLDevice getDLDevice(const at::Tensor &tensor, const int64_t &device_id) {
DLDevice device;
device.device_id = device_id;
if (tensor.is_cuda()) {
ctx.device_type = DLDeviceType::kDLGPU;
device.device_type = DLDeviceType::kDLGPU;
} else {
ctx.device_type = DLDeviceType::kDLCPU;
device.device_type = DLDeviceType::kDLCPU;
}
return ctx;
return device;
}

static at::DeviceType getATenDeviceType(DLDeviceType device_type) {
Expand Down Expand Up @@ -145,7 +145,7 @@ at::ScalarType toScalarType(const DLDataType &dtype) {
}

torch::Tensor fromDLPack(const DLTensor *src) {
at::DeviceType device_type = getATenDeviceType(src->ctx.device_type);
at::DeviceType device_type = getATenDeviceType(src->device.device_type);
at::ScalarType stype = toScalarType(src->dtype);
// torch::Device device(device_type, src->ctx.device_id);
torch::Device device(device_type, -1);
Expand Down Expand Up @@ -176,7 +176,7 @@ DLManagedTensor *toManagedDLPack(const torch::Tensor &src_) {
if (src.is_cuda()) {
device_id = src.get_device();
}
atDLMTensor->tensor.dl_tensor.ctx = getDLContext(src, device_id);
atDLMTensor->tensor.dl_tensor.device = getDLDevice(src, device_id);
atDLMTensor->tensor.dl_tensor.ndim = src.dim();
atDLMTensor->tensor.dl_tensor.dtype = getDLDataType(src);
atDLMTensor->tensor.dl_tensor.shape = const_cast<int64_t *>(src.sizes().data());
Expand Down
12 changes: 6 additions & 6 deletions src/serialization/RDB/decoder/current/v1/decode_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ void *RAI_RDBLoadTensor_v1(RedisModuleIO *io) {
int64_t *shape = NULL;
int64_t *strides = NULL;

DLContext ctx;
ctx.device_type = RedisModule_LoadUnsigned(io);
ctx.device_id = RedisModule_LoadUnsigned(io);
DLDevice device;
device.device_type = RedisModule_LoadUnsigned(io);
device.device_id = RedisModule_LoadUnsigned(io);
if (RedisModule_IsIOError(io))
goto cleanup;

// For now we only support CPU tensors (except during model and script run)
assert(ctx.device_type == kDLCPU);
assert(ctx.device_id == 0);
assert(device.device_type == kDLCPU);
assert(device.device_id == 0);

DLDataType dtype;
dtype.bits = RedisModule_LoadUnsigned(io);
Expand Down Expand Up @@ -49,7 +49,7 @@ void *RAI_RDBLoadTensor_v1(RedisModuleIO *io) {
goto cleanup;

RAI_Tensor *ret = RAI_TensorNew();
ret->tensor = (DLManagedTensor){.dl_tensor = (DLTensor){.ctx = ctx,
ret->tensor = (DLManagedTensor){.dl_tensor = (DLTensor){.device = device,
.data = data,
.ndim = ndims,
.dtype = dtype,
Expand Down
12 changes: 6 additions & 6 deletions src/serialization/RDB/decoder/previous/v0/decode_v0.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ void *RAI_RDBLoadTensor_v0(RedisModuleIO *io) {
int64_t *shape = NULL;
int64_t *strides = NULL;

DLContext ctx;
ctx.device_type = RedisModule_LoadUnsigned(io);
ctx.device_id = RedisModule_LoadUnsigned(io);
DLDevice device;
device.device_type = RedisModule_LoadUnsigned(io);
device.device_id = RedisModule_LoadUnsigned(io);
if (RedisModule_IsIOError(io))
goto cleanup;

// For now we only support CPU tensors (except during model and script run)
assert(ctx.device_type == kDLCPU);
assert(ctx.device_id == 0);
assert(device.device_type == kDLCPU);
assert(device.device_id == 0);

DLDataType dtype;
dtype.bits = RedisModule_LoadUnsigned(io);
Expand Down Expand Up @@ -42,7 +42,7 @@ void *RAI_RDBLoadTensor_v0(RedisModuleIO *io) {
goto cleanup;

RAI_Tensor *ret = RAI_TensorNew();
ret->tensor = (DLManagedTensor){.dl_tensor = (DLTensor){.ctx = ctx,
ret->tensor = (DLManagedTensor){.dl_tensor = (DLTensor){.device = device,
.data = data,
.ndim = ndims,
.dtype = dtype,
Expand Down
4 changes: 2 additions & 2 deletions src/serialization/RDB/encoder/v1/encode_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ void RAI_RDBSaveTensor_v1(RedisModuleIO *io, void *value) {

size_t ndim = tensor->tensor.dl_tensor.ndim;

RedisModule_SaveUnsigned(io, tensor->tensor.dl_tensor.ctx.device_type);
RedisModule_SaveUnsigned(io, tensor->tensor.dl_tensor.ctx.device_id);
RedisModule_SaveUnsigned(io, tensor->tensor.dl_tensor.device.device_type);
RedisModule_SaveUnsigned(io, tensor->tensor.dl_tensor.device.device_id);
RedisModule_SaveUnsigned(io, tensor->tensor.dl_tensor.dtype.bits);
RedisModule_SaveUnsigned(io, tensor->tensor.dl_tensor.dtype.code);
RedisModule_SaveUnsigned(io, tensor->tensor.dl_tensor.dtype.lanes);
Expand Down
10 changes: 5 additions & 5 deletions src/tensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ RAI_Tensor *RAI_TensorCreateWithDLDataType(DLDataType dtype, long long *dims, in
strides[i] *= strides[i + 1] * shape[i + 1];
}

DLContext ctx = (DLContext){.device_type = kDLCPU, .device_id = 0};
DLDevice device = (DLDevice){.device_type = kDLCPU, .device_id = 0};
void *data = NULL;
switch (tensorAllocMode) {
case TENSORALLOC_ALLOC:
Expand All @@ -140,7 +140,7 @@ RAI_Tensor *RAI_TensorCreateWithDLDataType(DLDataType dtype, long long *dims, in
break;
}

ret->tensor = (DLManagedTensor){.dl_tensor = (DLTensor){.ctx = ctx,
ret->tensor = (DLManagedTensor){.dl_tensor = (DLTensor){.device = device,
.data = data,
.ndim = ndims,
.dtype = dtype,
Expand Down Expand Up @@ -185,7 +185,7 @@ RAI_Tensor *_TensorCreateWithDLDataTypeAndRString(DLDataType dtype, size_t dtype
strides[i] *= strides[i + 1] * shape[i + 1];
}

DLContext ctx = (DLContext){.device_type = kDLCPU, .device_id = 0};
DLDevice device = (DLDevice){.device_type = kDLCPU, .device_id = 0};
size_t nbytes = len * dtypeSize;

size_t blob_len;
Expand All @@ -201,7 +201,7 @@ RAI_Tensor *_TensorCreateWithDLDataTypeAndRString(DLDataType dtype, size_t dtype
RAI_HoldString(NULL, rstr);

RAI_Tensor *ret = RAI_TensorNew();
ret->tensor = (DLManagedTensor){.dl_tensor = (DLTensor){.ctx = ctx,
ret->tensor = (DLManagedTensor){.dl_tensor = (DLTensor){.device = device,
.data = data,
.ndim = ndims,
.dtype = dtype,
Expand Down Expand Up @@ -342,7 +342,7 @@ RAI_Tensor *RAI_TensorCreateFromDLTensor(DLManagedTensor *dl_tensor) {
RAI_Tensor *ret = RAI_TensorNew();

ret->tensor =
(DLManagedTensor){.dl_tensor = (DLTensor){.ctx = dl_tensor->dl_tensor.ctx,
(DLManagedTensor){.dl_tensor = (DLTensor){.device = dl_tensor->dl_tensor.device,
.data = dl_tensor->dl_tensor.data,
.ndim = dl_tensor->dl_tensor.ndim,
.dtype = dl_tensor->dl_tensor.dtype,
Expand Down