xref: /honee/include/smartsim-impl.h (revision 0c608af58d6c66f4fcbe6fff5e0f907584234584)
1 // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors.
2 // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause
3 #pragma once
4 
5 #include <c_client.h>
6 #include <c_dataset.h>
7 #include <honee.h>
8 #include <petscsys.h>
9 #include <smartsim.h>
10 #include <sr_enums.h>
11 
12 #if defined(__clang_analyzer__)
13 void PetscCallSmartRedis(SRError);
14 #else
15 #define PetscCallSmartRedis(...)                                                                                                   \
16   do {                                                                                                                             \
17     SRError   ierr_smartredis_call_q_;                                                                                             \
18     PetscBool disable_calls = PETSC_FALSE;                                                                                         \
19     PetscStackUpdateLine;                                                                                                          \
20     PetscCall(PetscOptionsGetBool(NULL, NULL, "-smartsim_disable_calls", &disable_calls, NULL));                                   \
21     if (disable_calls == PETSC_TRUE) break;                                                                                        \
22     ierr_smartredis_call_q_ = __VA_ARGS__;                                                                                         \
23     if (PetscUnlikely(ierr_smartredis_call_q_ != SRNoError))                                                                       \
24       SETERRQ(PETSC_COMM_SELF, (PetscErrorCode)ierr_smartredis_call_q_, "SmartRedis Error (Code %d): %s", ierr_smartredis_call_q_, \
25               SRGetLastError());                                                                                                   \
26   } while (0)
27 #endif
28 
29 typedef struct {
30   void    *client;
31   char     rank_id_name[16];
32   PetscInt collocated_database_num_ranks;
33 } *SmartSimData;
34 
35 PetscErrorCode HoneeGetSmartSimData(Honee honee, SmartSimData *smartsim);
36 
37 PetscErrorCode SmartRedisVerifyPutTensor(void *c_client, const char *name, const size_t name_length);
38 
39 #if defined(PETSC_USE_64BIT_INDICES)
40 #define SRMetadataTypePetscInt SRMetadataTypeInt64
41 #else
42 #define SRMetadataTypePetscInt SRMetadataTypeInt32
43 #endif
44