Skip to content

Commit 0d00df4

Browse files
committed
- copy tensor blob when creating RAI_Tensor
- Do not shallow copy when save tensor outputs to keyspace after MODELRUN
1 parent cc0ff36 commit 0d00df4

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/DAG/dag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static int _StoreTensorInKeySpace(RedisModuleCtx *ctx, RAI_Tensor *tensor,
122122
RedisModule_ReplyWithError(ctx, "ERR could not save tensor");
123123
goto clean_up;
124124
}
125-
if (RedisModule_ModuleTypeSetValue(key, RedisAI_TensorType, RAI_TensorGetShallowCopy(tensor)) !=
125+
if (RedisModule_ModuleTypeSetValue(key, RedisAI_TensorType, tensor) !=
126126
REDISMODULE_OK) {
127127
RedisModule_ReplyWithError(ctx, "ERR could not save tensor");
128128
RedisModule_CloseKey(key);

src/tensor.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "rmutil/alloc.h"
1616
#include "tensor_struct.h"
1717
#include "util/dict.h"
18+
#include "util/string_utils.h"
1819
#include <assert.h>
1920
#include <pthread.h>
2021
#include <stddef.h>
@@ -162,7 +163,7 @@ void RAI_RStringDataTensorDeleter(DLManagedTensor *arg) {
162163
RedisModuleString *rstr = (RedisModuleString *)arg->manager_ctx;
163164
RedisModule_FreeString(NULL, rstr);
164165
}
165-
166+
RedisModule_Free(arg->dl_tensor.data);
166167
RedisModule_Free(arg);
167168
}
168169

@@ -189,7 +190,10 @@ RAI_Tensor *RAI_TensorCreateWithDLDataTypeAndRString(DLDataType dtype, long long
189190

190191
DLContext ctx = (DLContext){.device_type = kDLCPU, .device_id = 0};
191192

192-
char *data = (char *)RedisModule_StringPtrLen(rstr, NULL);
193+
long long nbytes = len*dtypeSize;
194+
195+
char *data = RedisModule_Alloc(nbytes);
196+
memcpy(data, RedisModule_StringPtrLen(rstr, NULL), nbytes);
193197

194198
ret->tensor = (DLManagedTensor){.dl_tensor = (DLTensor){.ctx = ctx,
195199
.data = data,

0 commit comments

Comments
 (0)