Skip to content

Commit 21d6cd6

Browse files
UCT/GDR_COPY: Use fast-path cache lookup
1 parent 4a8fa51 commit 21d6cd6

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/ucs/memory/rcache.inl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define UCS_RCACHE_INL_
99

1010
#include "rcache_int.h"
11+
#include <ucs/profile/profile.h>
1112

1213
static UCS_F_ALWAYS_INLINE int
1314
ucs_rcache_region_test(ucs_rcache_region_t *region, int prot, size_t alignment)
@@ -80,6 +81,17 @@ ucs_rcache_lookup_unsafe(ucs_rcache_t *rcache, void *address, size_t length,
8081
return region;
8182
}
8283

84+
static UCS_F_ALWAYS_INLINE ucs_rcache_region_t *
85+
ucs_rcache_lookup(ucs_rcache_t *rcache, void *address, size_t length,
86+
size_t alignment, int prot)
87+
{
88+
ucs_rcache_region_t *region;
89+
90+
ucs_rw_spinlock_read_lock(&rcache->pgt_lock);
91+
region = ucs_rcache_lookup_unsafe(rcache, address, length, alignment, prot);
92+
ucs_rw_spinlock_read_unlock(&rcache->pgt_lock);
93+
return region;
94+
}
8395

8496
static UCS_F_ALWAYS_INLINE void
8597
ucs_rcache_region_put_unsafe(ucs_rcache_t *rcache, ucs_rcache_region_t *region)

src/uct/cuda/gdr_copy/gdr_copy_md.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <ucs/sys/ptr_arith.h>
1818
#include <ucs/debug/memtrack_int.h>
1919
#include <ucs/time/time.h>
20+
#include <ucs/memory/rcache.inl>
2021
#include <ucs/type/class.h>
2122
#include <ucs/profile/profile.h>
2223
#include <ucm/api/ucm.h>
@@ -357,12 +358,19 @@ uct_gdr_copy_mem_rcache_reg(uct_md_h uct_md, void *address, size_t length,
357358
ucs_status_t status;
358359
uct_gdr_copy_mem_t *memh;
359360

361+
rregion = ucs_rcache_lookup(md->rcache, address, length, GPU_PAGE_SIZE,
362+
PROT_READ | PROT_WRITE);
363+
if (rregion != NULL) {
364+
goto out;
365+
}
366+
360367
status = ucs_rcache_get(md->rcache, address, length, GPU_PAGE_SIZE,
361368
PROT_READ | PROT_WRITE, &flags, &rregion);
362369
if (status != UCS_OK) {
363370
return status;
364371
}
365372

373+
out:
366374
ucs_assert(rregion->refcount > 0);
367375
memh = &ucs_derived_of(rregion, uct_gdr_copy_rcache_region_t)->memh;
368376
*memh_p = memh;

0 commit comments

Comments
 (0)