diff --git a/Makefile b/Makefile index e6018b74..022d8d8b 100644 --- a/Makefile +++ b/Makefile @@ -19,4 +19,4 @@ build-in-docker: check-cuda-hook-consistency: python3 hack/check_cuda_hook_consistency.py -.PHONY: check-cuda-hook-consistency +.PHONY: check-cuda-hook-consistency \ No newline at end of file diff --git a/src/utils.c b/src/utils.c index e96b43e3..4b52a5f3 100755 --- a/src/utils.c +++ b/src/utils.c @@ -13,9 +13,10 @@ #include "multiprocess/multiprocess_memory_limit.h" const char* unified_lock="/tmp/vgpulock/lock"; -static int lock_fd = -1; + extern size_t context_size; extern int cuda_to_nvml_map_array[CUDA_DEVICE_MAX_COUNT]; +static int unified_lock_fd = -1; // 0 unified_lock lock success // -1 unified_lock lock fail diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ae39f322..8e58cbbf 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -36,6 +36,12 @@ foreach(TEST_SCRIPT ${TEST_SCRIPTS}) list(APPEND TEST_TARGET_NAMES_LIST ${TEST_TARGET_NAME}) if (TEST_TARGET_NAME STREQUAL "test_postinit_owner_death") target_link_libraries(${TEST_TARGET_NAME} -lrt -lpthread) + elseif(TEST_TARGET_NAME STREQUAL "bench_lock") + # Tell CMake to compile utils.c together with bench_lock.c + target_sources(${TEST_TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src/utils.c) + # Add the include directory so it can find the headers + target_include_directories(${TEST_TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src) + target_link_libraries(${TEST_TARGET_NAME} -lrt -lpthread) else() target_link_libraries(${TEST_TARGET_NAME} -lrt -lpthread -lnvidia-ml -lcuda -lcudart -L${CUDA_HOME}/lib64) diff --git a/test/test_alloc_concurrent.cu b/test/test_alloc_concurrent.cu new file mode 100644 index 00000000..3d77dafd --- /dev/null +++ b/test/test_alloc_concurrent.cu @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include + +#define NUM_WORKERS 4 +#define ITERATIONS 10 + +void worker_task(int worker_id) { + void *ptr = NULL; + for (int i = 0; i < ITERATIONS; i++) { + // Allocate 1MB to trigger HAMi-core's memory interception + cudaError_t err = cudaMalloc(&ptr, 1024 * 1024); + if (err != cudaSuccess) { + printf("Worker %d failed allocation: %s\n", worker_id, cudaGetErrorString(err)); + exit(1); + } + cudaFree(ptr); + } + printf("Worker %d completed successfully.\n", worker_id); + exit(0); +} + +int main() { + printf("Starting %d concurrent workers...\n", NUM_WORKERS); + + for (int i = 0; i < NUM_WORKERS; i++) { + pid_t pid = fork(); + if (pid == 0) { + // Child process + worker_task(i); + } else if (pid < 0) { + printf("Fork failed.\n"); + return 1; + } + } + + // Parent waits for all children to finish + int status; + while (wait(&status) > 0); + + printf("All workers finished.\n"); + return 0; +} \ No newline at end of file