Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
hip_hijack.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation, Los Alamos National Laboratory
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18// helper objects related to Realm's hijacking of the HIP runtime API
19
20#ifndef REALM_HIP_HIJACK_H
21#define REALM_HIP_HIJACK_H
22
23#include "realm/mutex.h"
24
25#include <set>
26#include <vector>
27
28namespace Realm {
29 namespace Hip {
30
31 // this flag will be set on the first call into any of this hijack code - if
32 // an application is linked with -lcudart, we will NOT be hijacking the
33 // application's calls, and the cuda module needs to know that)
34 extern bool cudart_hijack_active;
35
36 // files compiled with nvcc will use global registrations of modules, variables, etc.
37 // that get broadcast to all contexts
38
39 struct FatBin {
40 int magic; // magic number
42 const unsigned long long *data;
44 };
45
48 const void *host_fun;
49 const char *device_fun;
50
51 RegisteredFunction(const FatBin *_fat_bin, const void *_host_fun,
52 const char *_device_fun);
53 };
54
57 const void *host_var;
58 const char *device_name;
60 int size;
62 bool global;
63 bool managed;
64
65 RegisteredVariable(const FatBin *_fat_bin, const void *_host_var,
66 const char *_device_name, bool _external, int _size,
67 bool _constant, bool _global, bool _managed);
68 };
69
70 class GPU;
71
73 protected:
76
78
79 public:
80 // called by a GPU when it has created its context - will result in calls back
81 // into the GPU for any modules/variables/whatever already registered
82 static void add_gpu_context(GPU *gpu);
83 static void remove_gpu_context(GPU *gpu);
84
85 // called by __cuda(un)RegisterFatBinary
86 static void register_fat_binary(FatBin *fatbin);
87 static void unregister_fat_binary(FatBin *fatbin);
88
89 // called by __cudaRegisterVar
91
92 // called by __cudaRegisterFunction
94
95 protected:
97 std::set<GPU *> active_gpus;
98 std::vector<FatBin *> fat_binaries;
99 std::vector<RegisteredVariable *> variables;
100 std::vector<RegisteredFunction *> functions;
101 };
102 }; // namespace Hip
103}; // namespace Realm
104
105#endif
Definition hip_internal.h:322
Definition hip_hijack.h:72
std::vector< RegisteredFunction * > functions
Definition hip_hijack.h:100
static void add_gpu_context(GPU *gpu)
static void register_function(RegisteredFunction *func)
static void remove_gpu_context(GPU *gpu)
static GlobalRegistrations & get_global_registrations(void)
static void unregister_fat_binary(FatBin *fatbin)
static void register_variable(RegisteredVariable *var)
std::vector< RegisteredVariable * > variables
Definition hip_hijack.h:99
std::set< GPU * > active_gpus
Definition hip_hijack.h:97
std::vector< FatBin * > fat_binaries
Definition hip_hijack.h:98
static void register_fat_binary(FatBin *fatbin)
Mutex mutex
Definition hip_hijack.h:96
Definition mutex.h:223
bool cudart_hijack_active
Definition activemsg.h:38
Definition hip_hijack.h:39
void * filename_or_fatbins
Definition hip_hijack.h:43
int version
Definition hip_hijack.h:41
const unsigned long long * data
Definition hip_hijack.h:42
int magic
Definition hip_hijack.h:40
Definition hip_hijack.h:46
const FatBin * fat_bin
Definition hip_hijack.h:47
const char * device_fun
Definition hip_hijack.h:49
const void * host_fun
Definition hip_hijack.h:48
RegisteredFunction(const FatBin *_fat_bin, const void *_host_fun, const char *_device_fun)
Definition hip_hijack.h:55
int size
Definition hip_hijack.h:60
bool global
Definition hip_hijack.h:62
const char * device_name
Definition hip_hijack.h:58
bool external
Definition hip_hijack.h:59
RegisteredVariable(const FatBin *_fat_bin, const void *_host_var, const char *_device_name, bool _external, int _size, bool _constant, bool _global, bool _managed)
bool managed
Definition hip_hijack.h:63
const FatBin * fat_bin
Definition hip_hijack.h:56
bool constant
Definition hip_hijack.h:61
const void * host_var
Definition hip_hijack.h:57