Skip to content

Commit 80a80f3

Browse files
committed
hmem: Add dmabuf support detection infrastructure
feat: Add dmabuf capability tracking for HMEM interfaces Problem: - Need infrastructure to detect and query dmabuf support per HMEM interface - Providers need to know if dmabuf is available before attempting registration Solution: - Added ofi_hmem_is_dmabuf_supported() query function in include/ofi_hmem.h - Implemented dmabuf support detection in src/hmem_cuda.c - Implemented dmabuf support detection in src/hmem_neuron.c - Added stub implementations in src/hmem_rocr.c and src/hmem_synapseai.c - Updated src/hmem.c to expose the new interface Testing: - Verified compilation with and without CUDA/Neuron support - Tested query function returns correct values for each interface Sim Issue: - N/A Signed-off-by: Nick Mazzilli <[email protected]>
1 parent cbab404 commit 80a80f3

File tree

5 files changed

+61
-9
lines changed

5 files changed

+61
-9
lines changed

include/ofi_hmem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ int rocr_dev_reg_copy_from_hmem(uint64_t handle, void *dest, const void *src,
169169
int rocr_hmem_get_dmabuf_fd(const void *addr, uint64_t size, int *dmabuf_fd,
170170
uint64_t *offset);
171171
int rocr_hmem_put_dmabuf_fd(int fd);
172+
bool rocr_is_dmabuf_requested(void);
172173

173174
int cuda_copy_to_dev(uint64_t device, void *dev, const void *host, size_t size);
174175
int cuda_copy_from_dev(uint64_t device, void *host, const void *dev, size_t size);
@@ -193,6 +194,7 @@ bool cuda_is_ipc_enabled(void);
193194
int cuda_get_ipc_handle_size(size_t *size);
194195
bool cuda_is_gdrcopy_enabled(void);
195196
bool cuda_is_dmabuf_supported(void);
197+
bool cuda_is_dmabuf_requested(void);
196198
int cuda_get_dmabuf_fd(const void *addr, uint64_t size, int *fd,
197199
uint64_t *offset);
198200
int cuda_put_dmabuf_fd(int fd);
@@ -257,6 +259,7 @@ void neuron_free(void **handle);
257259
int neuron_get_dmabuf_fd(const void *addr, uint64_t size, int *fd,
258260
uint64_t *offset);
259261
int neuron_put_dmabuf_fd(int fd);
262+
bool neuron_is_dmabuf_requested(void);
260263

261264
int synapseai_init(void);
262265
int synapseai_cleanup(void);
@@ -270,6 +273,7 @@ bool synapseai_is_addr_valid(const void *addr, uint64_t *device,
270273
uint64_t *flags);
271274
int synapseai_host_register(void *ptr, size_t size);
272275
int synapseai_host_unregister(void *ptr);
276+
bool synapseai_is_dmabuf_requested(void);
273277

274278
static inline int ofi_memcpy(uint64_t device, void *dest, const void *src,
275279
size_t size)

src/hmem_cuda.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ int cuda_hmem_init(void)
786786
"this variable is not checked. (default: true)");
787787

788788
fi_param_define(NULL, "hmem_cuda_use_dmabuf", FI_PARAM_BOOL,
789-
"Use dma-buf for sharing buffer with hardware. (default:true)");
789+
"Use dma-buf for sharing buffer with hardware. (default: true)");
790790

791791
ret = cuda_hmem_dl_init();
792792
if (ret != FI_SUCCESS)
@@ -959,13 +959,16 @@ bool cuda_is_gdrcopy_enabled(void)
959959
return cuda_attr.use_gdrcopy;
960960
}
961961

962-
bool cuda_is_dmabuf_supported(void)
962+
bool cuda_is_dmabuf_requested(void)
963963
{
964964
int use_dmabuf = 1;
965-
966965
fi_param_get_bool(NULL, "hmem_cuda_use_dmabuf", &use_dmabuf);
966+
return use_dmabuf != 0;
967+
}
967968

968-
return use_dmabuf && cuda_attr.dmabuf_supported;
969+
bool cuda_is_dmabuf_supported(void)
970+
{
971+
return cuda_is_dmabuf_requested() && cuda_attr.dmabuf_supported;
969972
}
970973

971974
#else
@@ -1068,6 +1071,11 @@ bool cuda_is_dmabuf_supported(void)
10681071
return false;
10691072
}
10701073

1074+
bool cuda_is_dmabuf_requested(void)
1075+
{
1076+
return false;
1077+
}
1078+
10711079
int cuda_get_dmabuf_fd(const void *addr, uint64_t size, int *fd,
10721080
uint64_t *offset)
10731081
{

src/hmem_neuron.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ int neuron_hmem_init(void)
152152
int ret;
153153
uint32_t total_nc_count;
154154

155+
fi_param_define(NULL, "hmem_neuron_use_dmabuf", FI_PARAM_BOOL,
156+
"Use DMABUF for Neuron device memory registration. (Default: true)");
157+
155158
ret = neuron_dl_init();
156159
if (ret)
157160
return ret;
@@ -255,6 +258,13 @@ int neuron_put_dmabuf_fd(int fd)
255258
return FI_SUCCESS;
256259
}
257260

261+
bool neuron_is_dmabuf_requested(void)
262+
{
263+
int use_dmabuf = 1;
264+
fi_param_get_bool(NULL, "hmem_neuron_use_dmabuf", &use_dmabuf);
265+
return use_dmabuf != 0;
266+
}
267+
258268
#else
259269

260270
int neuron_copy_to_dev(uint64_t device, void *dev, const void *host, size_t size)
@@ -308,4 +318,9 @@ int neuron_put_dmabuf_fd(int fd)
308318
return -FI_ENOSYS;
309319
}
310320

321+
bool neuron_is_dmabuf_requested(void)
322+
{
323+
return false;
324+
}
325+
311326
#endif /* HAVE_NEURON */

src/hmem_rocr.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,8 @@ int rocr_hmem_init(void)
947947
"Threshold for switching to hsa memcpy for device-to-host"
948948
" copies. (Default 16384");
949949

950-
fi_param_define(NULL, "hmem_rocr_use_dmabuf", FI_PARAM_INT,
951-
"Use dma-buf for sharing buffer with hardware. (default:0)");
950+
fi_param_define(NULL, "hmem_rocr_use_dmabuf", FI_PARAM_BOOL,
951+
"Use dma-buf for sharing buffer with hardware. (default: true)");
952952

953953
ret = rocr_hmem_dl_init();
954954
if (ret != FI_SUCCESS)
@@ -1123,14 +1123,19 @@ int rocr_dev_reg_copy_from_hmem(uint64_t handle, void *dest, const void *src,
11231123
return FI_SUCCESS;
11241124
}
11251125

1126+
bool rocr_is_dmabuf_requested(void)
1127+
{
1128+
int use_dmabuf = 0;
1129+
fi_param_get_int(NULL, "hmem_rocr_use_dmabuf", &use_dmabuf);
1130+
return use_dmabuf != 0;
1131+
}
1132+
11261133
static bool rocr_is_dmabuf_supported(void)
11271134
{
11281135
hsa_status_t hsa_ret;
1129-
int use_dmabuf = 0;
11301136
bool dmabuf_support = false, dmabuf_kernel = false;
11311137

1132-
fi_param_get_int(NULL, "hmem_rocr_use_dmabuf", &use_dmabuf);
1133-
if (!use_dmabuf)
1138+
if (!rocr_is_dmabuf_requested())
11341139
goto out;
11351140

11361141
/* HSA_AMD_SYSTEM_INFO_DMABUF_SUPPORTED = 0x204, we use the number
@@ -1367,4 +1372,9 @@ int rocr_hmem_put_dmabuf_fd(int fd)
13671372
return -FI_ENOSYS;
13681373
}
13691374

1375+
bool rocr_is_dmabuf_requested(void)
1376+
{
1377+
return false;
1378+
}
1379+
13701380
#endif /* HAVE_ROCR */

src/hmem_synapseai.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ int synapseai_init(void)
106106
synStatus status;
107107
uint32_t device_count = 0;
108108

109+
fi_param_define(NULL, "hmem_synapseai_use_dmabuf", FI_PARAM_BOOL,
110+
"Use DMABUF for SynapseAI device memory registration. (Default: true)");
111+
109112
err = synapseai_dl_init();
110113
if (err)
111114
return err;
@@ -206,6 +209,13 @@ int synapseai_get_dmabuf_fd(const void *addr, uint64_t size, int *fd,
206209
return FI_SUCCESS;
207210
}
208211

212+
bool synapseai_is_dmabuf_requested(void)
213+
{
214+
int use_dmabuf = 1;
215+
fi_param_get_bool(NULL, "hmem_synapseai_use_dmabuf", &use_dmabuf);
216+
return use_dmabuf != 0;
217+
}
218+
209219
#else
210220
int synapseai_init(void)
211221
{
@@ -250,4 +260,9 @@ int synapseai_get_dmabuf_fd(const void *addr, uint64_t size, int *fd,
250260
{
251261
return -FI_ENOSYS;
252262
}
263+
264+
bool synapseai_is_dmabuf_requested(void)
265+
{
266+
return false;
267+
}
253268
#endif /* HAVE_SYNAPSEAI */

0 commit comments

Comments
 (0)