beehive-lab / TornadoVM

TornadoVM: A practical and efficient heterogeneous programming framework for managed languages
https://www.tornadovm.org
Apache License 2.0
1.19k stars 114 forks source link

Compilation of the PTX backend on WSL #256

Closed jjfumero closed 1 year ago

jjfumero commented 1 year ago

Describe the bug

The PTX backend does not compile on WSL due to configuration issues.

How To Reproduce

Provide a test-case and instructions of how to reproduce the issue.

make BAKEND=ptx

Expected behavior

I managed to compile the PTX backend with minor modifications in the Cmake file:

diff --git a/tornado-drivers/ptx-jni/src/main/cpp/CMakeLists.txt b/tornado-drivers/ptx-jni/src/main/cpp/CMakeLists.txt
index 049defa58..67b76d7cb 100644
--- a/tornado-drivers/ptx-jni/src/main/cpp/CMakeLists.txt
+++ b/tornado-drivers/ptx-jni/src/main/cpp/CMakeLists.txt
@@ -4,7 +4,7 @@ project (Tornado)
 find_package(JNI REQUIRED)

 set(CMAKE_BUILD_TYPE Release)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fpermissive -export-dynamic -fPIC ")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -export-dynamic -fPIC")
 set(CMAKE_VERBOSE_MAKEFILE on)

 include_directories(
@@ -27,17 +27,17 @@ add_library(tornado-ptx SHARED
                source/ptx_log.h)

 #Support for CUDA Integration
-FIND_PACKAGE(CUDA)
-if(CUDA_FOUND)
+#FIND_PACKAGE(CUDA)
+#if(CUDA_FOUND)
     include_directories(${CUDA_INCLUDE_DIRS})
     link_directories(tornado-ptx ${CUDA_TOOLKIT_ROOT_DIR})
     if(CMAKE_HOST_WIN32)
         set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} $ENV{PTX_LDFLAGS}")
     endif()
-    target_link_libraries(tornado-ptx ${JNI_LIB_DIRS} -lcuda)
+    target_link_libraries(tornado-ptx ${JNI_LIB_DIRS} "-L/usr/local/cuda/lib64/stubs -lcuda")
     if(CMAKE_HOST_WIN32)
         set_target_properties(tornado-ptx PROPERTIES PREFIX "")
     endif()
-else(CUDA_FOUND)
-    message("CUDA is not installed on this system.")
-endif()
+    #else(CUDA_FOUND)
+    #message("CUDA is not installed on this system.")
+    ##di#f()

After this, one option is to compile with the nvcc compiler instead of gcc:

export CC=/usr/local/cuda/bin/nvcc
make BACKEND=ptx

We could generalize this solution for the PTX backend. The major issue was that the libcuda.so was not found, even though the LD_LIBRARY_PATH was pointing to the right directory.

Computing system setup (please complete the following information):

Additional context

Add any other context about the problem here.


jjfumero commented 1 year ago

After this patch, we can run on with CUDA on the NVIDIA GPU within Windows WSL.

 tornado --devices
WARNING: Using incubator modules: jdk.incubator.foreign, jdk.incubator.vector

Number of Tornado drivers: 1
Driver: PTX
  Total number of PTX devices  : 1
  Tornado device=0:0  (DEFAULT)
        PTX -- PTX -- NVIDIA GeForce RTX 3070
                Global Memory Size: 8.0 GB
                Local Memory Size: 48.0 KB
                Workgroup Dimensions: 3
                Total Number of Block Threads: [2147483647, 65535, 65535]
                Max WorkGroup Configuration: [1024, 1024, 64]
                Device OpenCL C version: N/A
stratika commented 1 year ago

A fix is now merged. I will close this issue, and we can reopen it in case further discussion is required.