Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brodey | dynamic unified ptrs #65

Merged
merged 24 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
350c7d8
chore: bm
brodeynewman Oct 9, 2024
1ad672a
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Oct 9, 2024
59150ee
chore: merge
brodeynewman Oct 9, 2024
c7d0b7d
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Oct 11, 2024
29a919e
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Oct 14, 2024
233b8e9
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Oct 14, 2024
fc00189
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Oct 17, 2024
79ccd26
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Oct 23, 2024
38a351c
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Oct 29, 2024
ab2e209
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Nov 6, 2024
ccd7c31
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Nov 8, 2024
25cad41
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Nov 9, 2024
11f8e43
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Nov 11, 2024
8e3d836
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Nov 18, 2024
e20c750
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Nov 28, 2024
8f56379
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Dec 2, 2024
e5592dc
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Dec 3, 2024
aeef059
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Dec 7, 2024
83d1ebc
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Dec 16, 2024
5fb85af
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Dec 20, 2024
644f22a
Merge branch 'main' of github.com:kevmo314/scuda
brodeynewman Dec 20, 2024
da5e408
chore: dynamic unified pointers
brodeynewman Dec 23, 2024
322f75c
chore: check parent alloc
brodeynewman Dec 24, 2024
0f8452c
chore: error handling
brodeynewman Dec 24, 2024
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
22 changes: 22 additions & 0 deletions client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,28 @@ static void segfault(int sig, siginfo_t* info, void* unused) {
raise(SIGSEGV);
}

void maybe_copy_unified_arg(const int index, void* arg, enum cudaMemcpyKind kind)
brodeynewman marked this conversation as resolved.
Show resolved Hide resolved
{
auto& unified_devices = conns[index].unified_devices;
auto found = unified_devices.find(arg);
if (found != unified_devices.end())
{
std::cout << "found unified arg pointer; copying..." << std::endl;

void* ptr = found->first;
size_t size = found->second;

cudaError_t res = cudaMemcpy(ptr, ptr, size, kind);

if (res != cudaSuccess) {
std::cerr << "cudaMemcpy failed: " << cudaGetErrorString(res) << std::endl;
} else {
std::cout << "Successfully copied " << size << " bytes" << std::endl;
}
}
}


static void set_segfault_handlers() {
if (init > 0) {
return;
Expand Down
42 changes: 40 additions & 2 deletions codegen/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ def client_rpc_write(self, f):
)
)

def client_unified_copy(self, f, direction):
f.write(" maybe_copy_unified_arg(0, (void*){name}, cudaMemcpyDeviceToHost);\n".format(name=self.parameter.name, direction=direction))

@property
def server_declaration(self) -> str:
c = self.ptr.ptr_to.const
Expand Down Expand Up @@ -209,7 +212,24 @@ def client_rpc_write(self, f):
length=length,
)
)


def client_unified_copy(self, f, direction):
f.write(" maybe_copy_unified_arg(0, (void*){name}, {direction});\n".format(name=self.parameter.name, direction=direction))

if isinstance(self.length, int):
f.write(" for (int i = 0; i < {name}; i++)\n".format(name=self.length))
f.write(" maybe_copy_unified_arg(0, (void*)&{name}[i], {direction});\n".format(name=self.parameter.name, direction=direction))
else:
if hasattr(self.length.type, "ptr_to"):
brodeynewman marked this conversation as resolved.
Show resolved Hide resolved
f.write(" for (int i = 0; i < static_cast<int>(*{name}); i++)\n".format(name=self.length.name))
f.write(" maybe_copy_unified_arg(0, (void*)&{name}[i], {direction});\n".format(name=self.parameter.name, direction=direction))
else:
if hasattr(self.parameter.type, "ptr_to"):
f.write(" for (int i = 0; i < static_cast<int>({name}); i++)\n".format(name=self.length.name))
f.write(" maybe_copy_unified_arg(0, (void*)&{name}[i], {direction});\n".format(name=self.parameter.name, direction=direction))
else:
f.write(" for (int i = 0; i < static_cast<int>({name}); i++)\n".format(name=self.length.name))
f.write(" maybe_copy_unified_arg(0, (void*){name}[i], {direction});\n".format(name=self.parameter.name, direction=direction))

@property
def server_declaration(self) -> str:
Expand Down Expand Up @@ -330,6 +350,9 @@ def client_rpc_write(self, f):
def server_declaration(self) -> str:
return f" {self.ptr.format()} {self.parameter.name};\n" + \
f" std::size_t {self.parameter.name}_len;\n"

def client_unified_copy(self, f, direction):
f.write(" maybe_copy_unified_arg(0, (void*){name}, {direction});\n".format(name=self.parameter.name, direction=direction))

def server_rpc_read(self, f, index) -> Optional[str]:
if not self.send:
Expand Down Expand Up @@ -415,6 +438,12 @@ def server_declaration(self) -> str:
return f" {self.type_.format().replace("const", "")} {self.parameter.name};\n"
else:
return f" {self.type_.format()} {self.parameter.name};\n"

def client_unified_copy(self, f, direction):
if isinstance(self.type_, Pointer):
f.write(" maybe_copy_unified_arg(0, (void*){name}, {direction});\n".format(name=self.parameter.name, direction=direction))
else:
f.write(" maybe_copy_unified_arg(0, (void*)&{name}, {direction});\n".format(name=self.parameter.name, direction=direction))

def server_rpc_read(self, f):
if not self.send:
Expand Down Expand Up @@ -486,6 +515,9 @@ def server_rpc_read(self, f):
param_type=self.type_.ptr_to.format(),
)
)

def client_unified_copy(self, f, direction):
f.write(" maybe_copy_unified_arg(0, (void*){name}, {direction});\n".format(name=self.parameter.name, direction=direction))

@property
def server_reference(self) -> str:
Expand Down Expand Up @@ -761,6 +793,7 @@ def main():
"extern int rpc_wait_for_response(const int index);\n"
"extern int rpc_read(const int index, void *data, const std::size_t size);\n"
"extern int rpc_end_response(const int index, void *return_value);\n"
"void maybe_copy_unified_arg(const int index, void *arg, enum cudaMemcpyKind kind);\n"
"extern int rpc_close();\n\n"
)
for function, annotation, operations, disabled in functions_with_annotations:
Expand Down Expand Up @@ -798,6 +831,9 @@ def main():
)
f.write("{\n")

for operation in operations:
operation.client_unified_copy(f, "cudaMemcpyHostToDevice")

f.write(
" {return_type} return_value;\n".format(
return_type=function.return_type.format()
Expand Down Expand Up @@ -841,12 +877,14 @@ def main():
)
)

for operation in operations:
operation.client_unified_copy(f, "cudaMemcpyDeviceToHost")

if function.name.format() == "nvmlShutdown":
f.write(" if (rpc_close() < 0)\n")
f.write(" return {error_return};\n".format(error_return=error_const(function.return_type.format())))

f.write(" return return_value;\n")

f.write("}\n\n")

f.write("std::unordered_map<std::string, void *> functionMap = {\n")
Expand Down
Loading
Loading