Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions attach/nv_attach_impl/trampoline/default_trampoline.cu
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,16 @@ struct CommSharedMem {
uint64_t time_sum[8];
};

// IPC-based GPU maps (for x86 with CUDA IPC support)
const int BPF_MAP_TYPE_PERGPUTD_ARRAY_MAP = 1502;
const int BPF_MAP_TYPE_GPU_ARRAY_MAP = 1503; // non-per-thread, single-copy
// shared array
const int BPF_MAP_TYPE_GPU_RINGBUF_MAP = 1527;

// HOST-based GPU maps (for Tegra/platforms without CUDA IPC)
const int BPF_MAP_TYPE_PERGPUTD_ARRAY_HOST_MAP = 1512;
const int BPF_MAP_TYPE_GPU_ARRAY_HOST_MAP = 1513;

struct MapBasicInfo {
bool enabled;
int key_size;
Expand Down Expand Up @@ -198,6 +203,7 @@ extern "C" __noinline__ __device__ uint64_t _bpf_helper_ext_0001(
auto &req = global_data->req;
// CallRequest req;
const auto &map_info = ::map_info[map];
// IPC-based per-thread array map
if (map_info.map_type == BPF_MAP_TYPE_PERGPUTD_ARRAY_MAP) {
auto real_key = *(uint32_t *)(uintptr_t)key;
auto offset = array_map_offset(real_key, map_info, map);
Expand All @@ -212,6 +218,20 @@ extern "C" __noinline__ __device__ uint64_t _bpf_helper_ext_0001(
(uint64_t)real_key *
map_info.value_size);
}
// HOST-based per-thread array map (for Tegra)
if (map_info.map_type == BPF_MAP_TYPE_PERGPUTD_ARRAY_HOST_MAP) {
auto real_key = *(uint32_t *)(uintptr_t)key;
auto offset = array_map_offset(real_key, map_info, map);
asm("membar.sys;"); // Ensure CPU writes are visible to GPU
return (uint64_t)offset;
}
// HOST-based non-per-thread GPU array map (for Tegra)
if (map_info.map_type == BPF_MAP_TYPE_GPU_ARRAY_HOST_MAP) {
auto real_key = *(uint32_t *)(uintptr_t)key;
auto base = (char *)map_info.extra_buffer;
asm("membar.sys;"); // Ensure CPU writes are visible to GPU
return (uint64_t)(uintptr_t)(base + (uint64_t)real_key * map_info.value_size);
}
// printf("helper1 map %ld keysize=%d valuesize=%d\n", map,
// map_info.key_size, map_info.value_size);
simple_memcpy(&req.map_lookup.key, (void *)(uintptr_t)key,
Expand All @@ -229,6 +249,7 @@ extern "C" __noinline__ __device__ uint64_t _bpf_helper_ext_0002(
CommSharedMem *global_data = (CommSharedMem *)constData;
auto &req = global_data->req;
const auto &map_info = ::map_info[map];
// IPC-based per-thread array map
if (map_info.map_type == BPF_MAP_TYPE_PERGPUTD_ARRAY_MAP) {
auto real_key = *(uint32_t *)(uintptr_t)key;
auto offset = array_map_offset(real_key, map_info, map);
Expand All @@ -249,6 +270,24 @@ extern "C" __noinline__ __device__ uint64_t _bpf_helper_ext_0002(
asm("membar.sys; \n\t");
return 0;
}
// HOST-based per-thread array map (for Tegra)
if (map_info.map_type == BPF_MAP_TYPE_PERGPUTD_ARRAY_HOST_MAP) {
auto real_key = *(uint32_t *)(uintptr_t)key;
auto offset = array_map_offset(real_key, map_info, map);
simple_memcpy(offset, (void *)(uintptr_t)value,
map_info.value_size);
asm("membar.sys;"); // Ensure GPU writes are visible to CPU
return 0;
}
// HOST-based non-per-thread GPU array map (for Tegra)
if (map_info.map_type == BPF_MAP_TYPE_GPU_ARRAY_HOST_MAP) {
auto real_key = *(uint32_t *)(uintptr_t)key;
auto base = (char *)map_info.extra_buffer;
auto dst = (void *)(uintptr_t)(base + (uint64_t)real_key * map_info.value_size);
simple_memcpy(dst, (void *)(uintptr_t)value, map_info.value_size);
asm("membar.sys;"); // Ensure GPU writes are visible to CPU
return 0;
}
// printf("helper2 map %ld keysize=%d
// valuesize=%d\n",map,map_info.key_size,map_info.value_size);
simple_memcpy(&req.map_update.key, (void *)(uintptr_t)key,
Expand Down
Loading
Loading