Skip to content

Commit

Permalink
chore: unified pointer test
Browse files Browse the repository at this point in the history
  • Loading branch information
brodeynewman committed Dec 19, 2024
1 parent f687e92 commit 00d6915
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 1 addition & 3 deletions client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,12 @@ void cuda_memcpy_unified_ptrs(const int index, cudaMemcpyKind kind)
}
}

void* maybe_free_unified_mem(const int index, void *ptr)
void maybe_free_unified_mem(const int index, void *ptr)
{
for (const auto & [ dev_ptr, sz ] : conns[index].unified_devices) {
size_t size = reinterpret_cast<size_t>(sz);

if (dev_ptr == ptr) {
std::cout << "mem-unmapping device ptr: " << dev_ptr << " size " << size << std::endl;

munmap(dev_ptr, size);
return;
}
Expand Down
18 changes: 17 additions & 1 deletion local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ test_cublas_batched() {
fi
}

test_unified_mem() {
output=$(LD_PRELOAD="$libscuda_path" ./unified_pointer.o | tail -n 1)

if [[ "$output" == "Max error: 0" ]]; then
ansi_format "pass" "$pass_message"
else
ansi_format "fail" "vector_add failed. Got [$output]."
return 1
fi
}

#---- declare test cases ----#
declare -A test_cuda_avail=(
["function"]="test_cuda_available"
Expand Down Expand Up @@ -196,8 +207,13 @@ declare -A test_cublas_batched=(
["pass"]="Batched cublas works via test/cublas_batched.cu."
)

declare -A test_unified_mem=(
["function"]="test_unified_mem"
["pass"]="Unified memory works as expected."
)

#---- assign them to our associative array ----#
tests=("test_cuda_avail" "test_tensor_to_cuda" "test_tensor_to_cuda_to_cpu" "test_vector_add" "test_cudnn" "test_cublas_batched")
tests=("test_cuda_avail" "test_tensor_to_cuda" "test_tensor_to_cuda_to_cpu" "test_vector_add" "test_cudnn" "test_cublas_batched" "test_unified_mem")

test() {
build
Expand Down

0 comments on commit 00d6915

Please sign in to comment.