Skip to content

Commit 3bcd2d2

Browse files
TheAssembler1houjungithub-actions[bot]jeanbez
authored
Region info transfer struct type and helper functions (#247)
* Fix cache flush (#226) * Fix a thread race issue that may cause memory error when larger than cache max size data is transferred * Add a test that writes more data than server cache size * Fix CI run command * checkpoint * Switch variables such as count_0, start_0, and size0... to arrays This will reduce code duplication, reduce bugs, and make it easier to switch to support n-dimnesional data. * clang format * checkpoint * created better function names and documentation * remove * Committing clang-format changes * clang format * remove file * change for use helper function * fix bug with incorrect helper function call --------- Co-authored-by: Houjun Tang <htang4@lbl.gov> Co-authored-by: github-actions <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jean Luca Bez <jlbez@lbl.gov>
1 parent a93223d commit 3bcd2d2

File tree

10 files changed

+508
-769
lines changed

10 files changed

+508
-769
lines changed

src/api/pdc_client_connect.c

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3047,30 +3047,10 @@ pack_region_metadata(int ndim, uint64_t *offset, uint64_t *size, region_info_tra
30473047

30483048
FUNC_ENTER(NULL);
30493049
transfer->ndim = ndim;
3050-
if (ndim >= 1) {
3051-
transfer->start_0 = offset[0];
3052-
transfer->count_0 = size[0];
3053-
}
3054-
else {
3055-
transfer->start_0 = 0;
3056-
transfer->count_0 = 0;
3057-
}
3058-
if (ndim >= 2) {
3059-
transfer->count_1 = size[1];
3060-
transfer->start_1 = offset[1];
3061-
}
3062-
else {
3063-
transfer->start_1 = 0;
3064-
transfer->count_1 = 0;
3065-
}
3066-
if (ndim >= 3) {
3067-
transfer->count_2 = size[2];
3068-
transfer->start_2 = offset[2];
3069-
}
3070-
else {
3071-
transfer->start_2 = 0;
3072-
transfer->count_2 = 0;
3073-
}
3050+
3051+
PDC_copy_region_desc(offset, transfer->start, ndim, ndim);
3052+
PDC_copy_region_desc(size, transfer->count, ndim, ndim);
3053+
30743054
fflush(stdout);
30753055
FUNC_LEAVE(ret_value);
30763056
}
@@ -3521,16 +3501,9 @@ PDC_Client_transfer_request(void *buf, pdcid_t obj_id, uint32_t data_server_id,
35213501
in.access_type = access_type;
35223502
in.remote_unit = unit;
35233503
in.obj_id = obj_id;
3524-
in.obj_ndim = obj_ndim;
3525-
if (in.obj_ndim >= 1) {
3526-
in.obj_dim0 = obj_dims[0];
3527-
}
3528-
if (in.obj_ndim >= 2) {
3529-
in.obj_dim1 = obj_dims[1];
3530-
}
3531-
if (in.obj_ndim >= 3) {
3532-
in.obj_dim2 = obj_dims[2];
3533-
}
3504+
3505+
in.obj_ndim = obj_ndim;
3506+
PDC_copy_region_desc(obj_dims, in.obj_dims, in.obj_ndim, in.obj_ndim);
35343507

35353508
// Compute metadata server id
35363509
meta_server_id = PDC_get_server_by_obj_id(obj_id, pdc_server_num_g);
@@ -6586,8 +6559,8 @@ PDC_Client_read_with_storage_meta(int nobj, region_storage_meta_t **all_storage_
65866559
prev_fname = fname;
65876560

65886561
// TODO: currently assumes 1d data and 1 storage region per object
6589-
storage_start = all_storage_meta[i]->region_transfer.start_0;
6590-
storage_count = all_storage_meta[i]->region_transfer.count_0;
6562+
storage_start = all_storage_meta[i]->region_transfer.start[0];
6563+
storage_count = all_storage_meta[i]->region_transfer.count[0];
65916564
req_start = storage_start;
65926565
req_count = storage_count;
65936566
file_offset = all_storage_meta[i]->offset;

src/api/pdc_region/include/pdc_region.h

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@
2727

2828
#include "pdc_public.h"
2929
#include "pdc_obj.h"
30+
3031
#ifdef ENABLE_MPI
3132
#include "mpi.h"
3233
#endif
3334

35+
#define DIM_MAX 4
36+
3437
/**************************/
3538
/* Library Public Struct */
3639
/**************************/
@@ -46,6 +49,13 @@ struct pdc_region_info {
4649
size_t unit;
4750
};
4851

52+
// Similar structure PDC_region_info_t defined in pdc_obj_pkg.h
53+
typedef struct region_info_transfer_t {
54+
size_t ndim;
55+
uint64_t start[DIM_MAX];
56+
uint64_t count[DIM_MAX];
57+
} region_info_transfer_t;
58+
4959
typedef enum {
5060
PDC_TRANSFER_STATUS_COMPLETE = 0,
5161
PDC_TRANSFER_STATUS_PENDING = 1,
@@ -253,4 +263,129 @@ perr_t PDCreg_obtain_lock(pdcid_t obj_id, pdcid_t reg_id, pdc_access_t access_ty
253263
*/
254264
perr_t PDCreg_release_lock(pdcid_t obj_id, pdcid_t reg_id, pdc_access_t access_type);
255265

266+
/**
267+
* @brief Check if two region info transfers are identical.
268+
*
269+
* Compares two region info transfer structures (`reg1` and `reg2`) to determine if they
270+
* are equal. The comparison checks if all bytes within the structures match.
271+
*
272+
* @param reg1 [IN] Pointer to the first region info transfer to compare.
273+
* @param reg2 [IN] Pointer to the second region info transfer to compare.
274+
*
275+
* @return 1 if the region info transfers are identical, -1 otherwise.
276+
*/
277+
pbool_t PDC_region_info_transfer_t_is_equal(const region_info_transfer_t *reg1,
278+
const region_info_transfer_t *reg2);
279+
280+
/**
281+
* @brief Copy a region info transfer to another region.
282+
*
283+
* Copies the data from one region info transfer structure (`src_reg`) to another (`dest_reg`).
284+
*
285+
* @param src_reg [IN] Pointer to the source region info transfer to copy from.
286+
* @param dest_reg [OUT] Pointer to the destination region info transfer to copy to.
287+
*
288+
* @return Non-negative on success, negative on failure.
289+
*/
290+
perr_t PDC_copy_region_info_transfer_t(const region_info_transfer_t *src_reg,
291+
region_info_transfer_t * dest_reg);
292+
293+
/**
294+
* @brief Calculate the size of a region descriptor in bytes.
295+
*
296+
* This function computes the size of the region described by `src_reg` in bytes by
297+
* multiplying the size of each dimension by the element size (`unit`).
298+
* The size in bytes is computed as the product of all dimensions, scaled by `unit`.
299+
*
300+
* @param src_reg [IN] Pointer to the source region descriptor (in elements)
301+
* @param unit [IN] Size of each element in bytes
302+
* @param ndim [IN] Number of dimensions in the region descriptor
303+
*
304+
* @return The size of the region in bytes.
305+
*/
306+
uint64_t PDC_get_region_desc_size_bytes(uint64_t *src_reg, int unit, int ndim);
307+
308+
/**
309+
* @brief Calculate the size of a region descriptor in elements from region desccriptor in bytes.
310+
*
311+
* This function computes the size of the region described by `src_reg` in terms of the
312+
* number of elements by dividing the given byte size by the element size (`unit`).
313+
*
314+
* @param src_reg [IN] Pointer to the source region descriptor (in bytes)
315+
* @param unit [IN] Size of each element in bytes
316+
* @param ndim [IN] Number of dimensions in the region descriptor
317+
*
318+
* @return The size of the region in terms of the number of elements.
319+
*/
320+
uint64_t PDC_get_region_desc_size_from_bytes_to_elements(const uint64_t *src_reg, int unit, int ndim);
321+
322+
/**
323+
* @brief Calculate the total size of a region descriptor in elements.
324+
*
325+
* This function computes the total size of the region described by `src_reg`,
326+
* by multiplying the dimensions of the region. The size is returned in terms
327+
* of the number of elements, not bytes.
328+
*
329+
* @param src_reg [IN] Pointer to the source region descriptor (in elements)
330+
* @param ndim [IN] Number of dimensions in the region descriptor
331+
*
332+
* @return The total size of the region in terms of the number of elements.
333+
*/
334+
uint64_t PDC_get_region_desc_size(const uint64_t *src_reg, int ndim);
335+
336+
/**
337+
* @brief Convert a region descriptor from byte units to element units.
338+
*
339+
* Copies the region dimensions from the source descriptor to the destination descriptor,
340+
* converting each dimension from bytes to elements by dividing by the element size.
341+
* For each dimension i:
342+
* dest_reg[i] = src_reg[i] / unit
343+
*
344+
* Both source and destination pointers must be non-null.
345+
*
346+
* @param src_reg [IN] Pointer to the source region descriptor (in bytes)
347+
* @param dest_reg [OUT] Pointer to the destination region descriptor (in elements)
348+
* @param unit [IN] Size of each element in bytes
349+
* @param ndim [IN] Number of dimensions in the region
350+
*
351+
* @return Non-negative on success, negative on failure.
352+
*/
353+
perr_t PDC_copy_region_desc_bytes_to_elements(const uint64_t *src_reg, uint64_t *dest_reg, int unit,
354+
int ndim);
355+
356+
/**
357+
* @brief Copy a region descriptor from source to destination without unit scaling.
358+
*
359+
* Copies each dimension from the source region descriptor to the destination region
360+
* descriptor without applying any scaling. The number of dimensions may differ between
361+
* source and destination, in which case only the common number of dimensions is copied.
362+
*
363+
* Validates that both source and destination pointers are not NULL.
364+
*
365+
* @param src_reg [IN] Pointer to the source region descriptor
366+
* @param dest_reg [OUT] Pointer to the destination region descriptor
367+
* @param src_ndim [IN] Number of dimensions in the source region
368+
* @param dest_ndim [IN] Number of dimensions in the destination region
369+
*
370+
* @return Non-negative on success, negative on failure.
371+
*/
372+
perr_t PDC_copy_region_desc(const uint64_t *src_reg, uint64_t *dest_reg, int src_ndim, int dest_ndim);
373+
374+
/**
375+
* @brief Copy a region descriptor from element units to byte units.
376+
*
377+
* Sets each dimension of the destination region descriptor equal to the
378+
* corresponding dimension of the source descriptor multiplied by the element size in bytes.
379+
* For the i-th dimension: dest_reg[i] = src_reg[i] * unit
380+
*
381+
* @param src_reg [IN] Pointer to the source region descriptor (in elements)
382+
* @param dest_reg [OUT] Pointer to the destination region descriptor (in bytes)
383+
* @param unit [IN] Size of each element in bytes
384+
* @param dest_ndim [IN] Number of dimensions in the destination region
385+
*
386+
* @return Non-negative on success, negative on failure.
387+
*/
388+
perr_t PDC_copy_region_desc_elements_to_bytes(const uint64_t *src_reg, uint64_t *dest_reg, int unit,
389+
int dest_ndim);
390+
256391
#endif /* PDC_REGION_H */

src/server/include/pdc_client_server_common.h

Lines changed: 16 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ extern struct timeval last_cache_activity_timeval_g;
5353
#define NA_STRING_INFO_LEN ADDR_MAX / 2
5454
#define HOSTNAME_LEN ADDR_MAX / 8
5555
#define TMP_DIR_STRING_LEN ADDR_MAX / 2
56-
#define DIM_MAX 4
5756
#define TAG_LEN_MAX 2048
5857
#define OBJ_NAME_MAX TAG_LEN_MAX / 2
5958
#define PDC_SERVER_ID_INTERVEL 1000000000ull
@@ -198,14 +197,6 @@ typedef struct region_list_t {
198197
// NOTE: when modified, need to change init and deep_cp routines
199198
} region_list_t;
200199

201-
// Similar structure PDC_region_info_t defined in pdc_obj_pkg.h
202-
// TODO: currently only support upto four dimensions
203-
typedef struct region_info_transfer_t {
204-
size_t ndim;
205-
uint64_t start_0, start_1, start_2, start_3;
206-
uint64_t count_0, count_1, count_2, count_3;
207-
} region_info_transfer_t;
208-
209200
typedef struct pdc_metadata_transfer_t {
210201
int32_t user_id;
211202
const char *app_name;
@@ -791,9 +782,7 @@ typedef struct {
791782
hg_bulk_t local_bulk_handle;
792783
region_info_transfer_t remote_region;
793784
uint64_t obj_id;
794-
uint64_t obj_dim0;
795-
uint64_t obj_dim1;
796-
uint64_t obj_dim2;
785+
uint64_t obj_dims[DIM_MAX];
797786
size_t remote_unit;
798787
int32_t obj_ndim;
799788
uint32_t meta_server_id;
@@ -1251,45 +1240,17 @@ hg_proc_region_info_transfer_t(hg_proc_t proc, void *data)
12511240
return ret;
12521241
}
12531242

1254-
ret = hg_proc_uint64_t(proc, &struct_data->start_0);
1255-
if (ret != HG_SUCCESS) {
1256-
1257-
return ret;
1258-
}
1259-
ret = hg_proc_uint64_t(proc, &struct_data->start_1);
1260-
if (ret != HG_SUCCESS) {
1261-
1262-
return ret;
1263-
}
1264-
ret = hg_proc_uint64_t(proc, &struct_data->start_2);
1265-
if (ret != HG_SUCCESS) {
1266-
1267-
return ret;
1268-
}
1269-
ret = hg_proc_uint64_t(proc, &struct_data->start_3);
1270-
if (ret != HG_SUCCESS) {
1271-
1272-
return ret;
1273-
}
1274-
ret = hg_proc_uint64_t(proc, &struct_data->count_0);
1275-
if (ret != HG_SUCCESS) {
1276-
1277-
return ret;
1278-
}
1279-
ret = hg_proc_uint64_t(proc, &struct_data->count_1);
1280-
if (ret != HG_SUCCESS) {
1281-
1282-
return ret;
1283-
}
1284-
ret = hg_proc_uint64_t(proc, &struct_data->count_2);
1285-
if (ret != HG_SUCCESS) {
1286-
1287-
return ret;
1243+
for (int i = 0; i < DIM_MAX; i++) {
1244+
ret = hg_proc_uint64_t(proc, &(struct_data->start[i]));
1245+
if (ret != HG_SUCCESS) {
1246+
return ret;
1247+
}
12881248
}
1289-
ret = hg_proc_uint64_t(proc, &struct_data->count_3);
1290-
if (ret != HG_SUCCESS) {
1291-
1292-
return ret;
1249+
for (int i = 0; i < DIM_MAX; i++) {
1250+
ret = hg_proc_uint64_t(proc, &(struct_data->count[i]));
1251+
if (ret != HG_SUCCESS) {
1252+
return ret;
1253+
}
12931254
}
12941255

12951256
return ret;
@@ -2687,17 +2648,11 @@ hg_proc_transfer_request_in_t(hg_proc_t proc, void *data)
26872648
if (ret != HG_SUCCESS) {
26882649
return ret;
26892650
}
2690-
ret = hg_proc_uint64_t(proc, &struct_data->obj_dim0);
2691-
if (ret != HG_SUCCESS) {
2692-
return ret;
2693-
}
2694-
ret = hg_proc_uint64_t(proc, &struct_data->obj_dim1);
2695-
if (ret != HG_SUCCESS) {
2696-
return ret;
2697-
}
2698-
ret = hg_proc_uint64_t(proc, &struct_data->obj_dim2);
2699-
if (ret != HG_SUCCESS) {
2700-
return ret;
2651+
for (int i = 0; i < DIM_MAX; i++) {
2652+
ret = hg_proc_uint64_t(proc, &struct_data->obj_dims[i]);
2653+
if (ret != HG_SUCCESS) {
2654+
return ret;
2655+
}
27012656
}
27022657
ret = hg_proc_hg_size_t(proc, &struct_data->remote_unit);
27032658
if (ret != HG_SUCCESS) {

src/server/include/pdc_server_metadata.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,6 @@ perr_t PDC_Meta_Server_buf_map(buf_map_in_t *in, region_buf_map_t *new_buf_map_p
127127
*/
128128
perr_t PDC_Meta_Server_buf_unmap(buf_unmap_in_t *in, hg_handle_t *handle);
129129

130-
/**
131-
* Check if two regions are identical
132-
*
133-
* \param reg1 [IN] Region to compare
134-
* \param reg2 [IN] Region to compare
135-
*
136-
* \return 1 if they are the same/-1 otherwise
137-
*/
138-
pbool_t PDC_region_is_identical(region_info_transfer_t reg1, region_info_transfer_t reg2);
139-
140130
/**
141131
* Check if two regions overlap
142132
*

0 commit comments

Comments
 (0)