42
42
#include "opal/mca/rcache/base/base.h"
43
43
#include "opal/mca/rcache/rcache.h"
44
44
#include "opal/mca/accelerator/accelerator.h"
45
- #if OPAL_CUDA_GDR_SUPPORT
46
- #include "opal/cuda/common_cuda.h"
47
- #endif /* OPAL_CUDA_GDR_SUPPORT */
48
45
#include "opal/align.h"
49
46
#include "opal/util/sys_limits.h"
50
47
#include "rcache_grdma.h"
@@ -61,6 +58,7 @@ static int mca_rcache_grdma_invalidate_range(mca_rcache_base_module_t *rcache, v
61
58
static void mca_rcache_grdma_finalize (mca_rcache_base_module_t * rcache );
62
59
static bool mca_rcache_grdma_evict (mca_rcache_base_module_t * rcache );
63
60
static int mca_rcache_grdma_add_to_gc (mca_rcache_base_registration_t * grdma_reg );
61
+ static int check_for_accelerator_freed_memory (mca_rcache_base_module_t * rcache , void * addr , size_t size );
64
62
65
63
static inline bool registration_flags_cacheable (uint32_t flags )
66
64
{
@@ -75,9 +73,6 @@ static inline bool registration_is_cacheable(mca_rcache_base_registration_t *reg
75
73
return registration_flags_cacheable (reg -> flags );
76
74
}
77
75
78
- #if OPAL_CUDA_GDR_SUPPORT
79
- static int check_for_cuda_freed_memory (mca_rcache_base_module_t * rcache , void * addr , size_t size );
80
- #endif /* OPAL_CUDA_GDR_SUPPORT */
81
76
static void mca_rcache_grdma_cache_contructor (mca_rcache_grdma_cache_t * cache )
82
77
{
83
78
memset ((void * ) ((uintptr_t ) cache + sizeof (cache -> super )), 0 ,
@@ -328,8 +323,7 @@ static int mca_rcache_grdma_register(mca_rcache_base_module_t *rcache, void *add
328
323
base = OPAL_DOWN_ALIGN_PTR (addr , page_size , unsigned char * );
329
324
bound = OPAL_ALIGN_PTR ((intptr_t ) addr + size , page_size , unsigned char * ) - 1 ;
330
325
331
- #if OPAL_CUDA_GDR_SUPPORT
332
- if (flags & MCA_RCACHE_FLAGS_CUDA_GPU_MEM ) {
326
+ if (flags & MCA_RCACHE_FLAGS_ACCELERATOR_MEM ) {
333
327
size_t psize ;
334
328
int res = opal_accelerator .get_address_range (MCA_ACCELERATOR_NO_DEVICE_ID , addr , (void * * )& base , & psize );
335
329
if (OPAL_SUCCESS != res ) {
@@ -338,9 +332,8 @@ static int mca_rcache_grdma_register(mca_rcache_base_module_t *rcache, void *add
338
332
bound = base + psize - 1 ;
339
333
/* Check to see if this memory is in the cache and if it has been freed. If so,
340
334
* this call will boot it out of the cache. */
341
- check_for_cuda_freed_memory (rcache , base , psize );
335
+ check_for_accelerator_freed_memory (rcache , base , psize );
342
336
}
343
- #endif /* OPAL_CUDA_GDR_SUPPORT */
344
337
345
338
do_unregistration_gc (rcache );
346
339
@@ -378,11 +371,9 @@ static int mca_rcache_grdma_register(mca_rcache_base_module_t *rcache, void *add
378
371
grdma_reg -> flags = flags ;
379
372
grdma_reg -> access_flags = access_flags ;
380
373
grdma_reg -> ref_count = 1 ;
381
- #if OPAL_CUDA_GDR_SUPPORT
382
- if (flags & MCA_RCACHE_FLAGS_CUDA_GPU_MEM ) {
383
- mca_common_cuda_get_buffer_id (grdma_reg );
374
+ if (flags & MCA_RCACHE_FLAGS_ACCELERATOR_MEM ) {
375
+ opal_accelerator .get_buffer_id (MCA_ACCELERATOR_NO_DEVICE_ID , grdma_reg -> base , & grdma_reg -> gpu_bufID );
384
376
}
385
- #endif /* OPAL_CUDA_GDR_SUPPORT */
386
377
387
378
while (OPAL_ERR_OUT_OF_RESOURCE
388
379
== (rc = rcache_grdma -> resources .register_mem (rcache_grdma -> resources .reg_data , base ,
@@ -538,15 +529,34 @@ static int mca_rcache_grdma_invalidate_range(mca_rcache_base_module_t *rcache, v
538
529
& args );
539
530
}
540
531
532
+ /* Check to see if the memory was freed between the time it was stored in
533
+ * the registration cache and now. Return true if the memory was previously
534
+ * freed. This is indicated by the BUFFER_ID value in the registration cache
535
+ * not matching the BUFFER_ID of the buffer we are checking. Return false
536
+ * if the registration is still good.
537
+ */
538
+ static bool mca_rcache_accelerator_previously_freed_memory (mca_rcache_base_registration_t * reg )
539
+ {
540
+ int res ;
541
+ opal_accelerator_buffer_id_t buf_id ;
542
+ unsigned char * dbuf = reg -> base ;
543
+ opal_accelerator .get_buffer_id (MCA_ACCELERATOR_NO_DEVICE_ID , dbuf , & buf_id );
544
+ if (OPAL_UNLIKELY (res != OPAL_SUCCESS )) {
545
+ return true;
546
+ }
547
+ if (buf_id != reg -> gpu_bufID ) {
548
+ return true;
549
+ } else {
550
+ return false;
551
+ }
552
+ }
553
+
541
554
/* Make sure this registration request is not stale. In other words, ensure
542
555
* that we do not have a cuMemAlloc, cuMemFree, cuMemAlloc state. If we do
543
556
* kick out the regisrations and deregister. This function needs to be called
544
557
* with the rcache->vma_module->vma_lock held. */
545
- #if OPAL_CUDA_GDR_SUPPORT
546
-
547
- static int check_for_cuda_freed_memory (mca_rcache_base_module_t * rcache , void * addr , size_t size )
558
+ static int check_for_accelerator_freed_memory (mca_rcache_base_module_t * rcache , void * addr , size_t size )
548
559
{
549
- unsigned long long buf_id ;
550
560
mca_rcache_grdma_module_t * rcache_grdma = (mca_rcache_grdma_module_t * ) rcache ;
551
561
mca_rcache_base_registration_t * reg ;
552
562
@@ -556,7 +566,7 @@ static int check_for_cuda_freed_memory(mca_rcache_base_module_t *rcache, void *a
556
566
}
557
567
558
568
/* If not previously freed memory, just return 0 */
559
- if (!(mca_common_cuda_previously_freed_memory (reg ))) {
569
+ if (!(mca_rcache_accelerator_previously_freed_memory (reg ))) {
560
570
return OPAL_SUCCESS ;
561
571
}
562
572
@@ -566,7 +576,6 @@ static int check_for_cuda_freed_memory(mca_rcache_base_module_t *rcache, void *a
566
576
return mca_rcache_base_vma_iterate (rcache_grdma -> cache -> vma_module , addr , size , true, gc_add ,
567
577
NULL );
568
578
}
569
- #endif /* OPAL_CUDA_GDR_SUPPORT */
570
579
571
580
static void mca_rcache_grdma_finalize (mca_rcache_base_module_t * rcache )
572
581
{
0 commit comments