|
| 1 | +/** |
| 2 | + * script.h |
| 3 | + * |
| 4 | + * Contains headers for the helper methods for both creating, populating, |
| 5 | + * managing and destructing the PyTorch Script data structure. |
| 6 | + * |
| 7 | + */ |
| 8 | + |
| 9 | +#pragma once |
| 10 | + |
| 11 | +#include "err.h" |
| 12 | +#include "tensor.h" |
| 13 | +#include "script_struct.h" |
| 14 | +#include "redismodule.h" |
| 15 | + |
| 16 | +/** |
| 17 | + * Helper method to allocated and initialize a RAI_Script. Relies on Pytorch |
| 18 | + * backend `script_create` callback function. |
| 19 | + * |
| 20 | + * @param devicestr device string |
| 21 | + * @param tag script model tag |
| 22 | + * @param scriptdef encoded script definition |
| 23 | + * @param error error data structure to store error message in the case of |
| 24 | + * failures |
| 25 | + * @return RAI_Script script structure on success, or NULL if failed |
| 26 | + */ |
| 27 | +RAI_Script *RAI_ScriptCreate(const char *devicestr, RedisModuleString *tag, const char *scriptdef, |
| 28 | + RAI_Error *err); |
| 29 | + |
| 30 | +/** |
| 31 | + * Frees the memory of the RAI_Script when the script reference count reaches |
| 32 | + * 0. It is safe to call this function with a NULL input script. |
| 33 | + * |
| 34 | + * @param script input script to be freed |
| 35 | + * @param error error data structure to store error message in the case of |
| 36 | + * failures |
| 37 | + */ |
| 38 | +void RAI_ScriptFree(RAI_Script *script, RAI_Error *err); |
| 39 | + |
| 40 | +/** |
| 41 | + * Every call to this function, will make the RAI_Script 'script' requiring an |
| 42 | + * additional call to RAI_ScriptFree() in order to really free the script. |
| 43 | + * Returns a shallow copy of the script. |
| 44 | + * |
| 45 | + * @param script input script |
| 46 | + * @return script |
| 47 | + */ |
| 48 | +RAI_Script *RAI_ScriptGetShallowCopy(RAI_Script *script); |
| 49 | + |
| 50 | +/* Return REDISMODULE_ERR if there was an error getting the Script. |
| 51 | + * Return REDISMODULE_OK if the model value stored at key was correctly |
| 52 | + * returned and available at *model variable. */ |
| 53 | + |
| 54 | +/** |
| 55 | + * Helper method to get a Script from keyspace. In the case of failure the key |
| 56 | + * is closed and the error is replied ( no cleaning actions required ) |
| 57 | + * |
| 58 | + * @param ctx Context in which Redis modules operate |
| 59 | + * @param keyName key name |
| 60 | + * @param script destination script structure |
| 61 | + * @param mode key access mode |
| 62 | + * @return REDISMODULE_OK if the script value stored at key was correctly |
| 63 | + * returned and available at *script variable, or REDISMODULE_ERR if there was |
| 64 | + * an error getting the Script |
| 65 | + */ |
| 66 | +int RAI_GetScriptFromKeyspace(RedisModuleCtx *ctx, RedisModuleString *keyName, RAI_Script **script, |
| 67 | + int mode, RAI_Error *err); |
| 68 | + |
| 69 | +/** |
| 70 | + * When a module command is called in order to obtain the position of |
| 71 | + * keys, since it was flagged as "getkeys-api" during the registration, |
| 72 | + * the command implementation checks for this special call using the |
| 73 | + * RedisModule_IsKeysPositionRequest() API and uses this function in |
| 74 | + * order to report keys. |
| 75 | + * No real execution is done on this special call. |
| 76 | + * @param ctx Context in which Redis modules operate |
| 77 | + * @param argv Redis command arguments, as an array of strings |
| 78 | + * @param argc Redis command number of arguments |
| 79 | + * @return |
| 80 | + */ |
| 81 | +int RedisAI_ScriptRun_IsKeysPositionRequest_ReportKeys(RedisModuleCtx *ctx, |
| 82 | + RedisModuleString **argv, int argc); |
| 83 | + |
| 84 | +/** |
| 85 | + * When a module command is called in order to obtain the position of |
| 86 | + * keys, since it was flagged as "getkeys-api" during the registration, |
| 87 | + * the command implementation checks for this special call using the |
| 88 | + * RedisModule_IsKeysPositionRequest() API and uses this function in |
| 89 | + * order to report keys. |
| 90 | + * No real execution is done on this special call. |
| 91 | + * @param ctx Context in which Redis modules operate |
| 92 | + * @param argv Redis command arguments, as an array of strings |
| 93 | + * @param argc Redis command number of arguments |
| 94 | + * @return |
| 95 | + */ |
| 96 | +int RedisAI_ScriptExecute_IsKeysPositionRequest_ReportKeys(RedisModuleCtx *ctx, |
| 97 | + RedisModuleString **argv, int argc); |
| 98 | + |
| 99 | +/** |
| 100 | + * @brief Returns the redis module type representing a script. |
| 101 | + * @return redis module type representing a script. |
| 102 | + */ |
| 103 | +RedisModuleType *RAI_ScriptRedisType(void); |
0 commit comments