Skip to content

Commit

Permalink
another attempt for compiling main dll via gcc, still not working
Browse files Browse the repository at this point in the history
  • Loading branch information
joanglaunes committed Aug 11, 2021
1 parent 31f7280 commit d8f2d87
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
8 changes: 6 additions & 2 deletions keops/python_engine/compilation/Gpu_link_compile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
from keops.python_engine.compilation import link_compile
from keops.python_engine.config import build_path
from ctypes import create_string_buffer, CDLL, c_int
from ctypes import create_string_buffer, CDLL, c_int, RTLD_GLOBAL
from os import RTLD_LAZY
from keops.python_engine import jit_binary, use_cuda


Expand Down Expand Up @@ -32,7 +33,10 @@ def __init__(self):
+ self.low_level_code_extension
).encode("utf-8")
# we load the main dll that must be run in order to compile the code
self.my_c_dll = CDLL(jit_binary)
CDLL("libnvrtc.so", mode=RTLD_GLOBAL)
CDLL("libcuda.so", mode=RTLD_GLOBAL)
CDLL("libcudart.so", mode=RTLD_GLOBAL)
self.my_c_dll = CDLL(jit_binary, mode=RTLD_LAZY)
# actual dll to be called is the jit binary
self.true_dllname = jit_binary
# file to check for existence to detect compilation is needed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <nvrtc.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <stdio.h>
#include <iostream>
#include <sstream>
Expand All @@ -23,7 +24,7 @@
#include "utils.cpp"
#include "ranges_utils.cpp"

extern "C" __host__ int Compile(const char* ptx_file_name, const char* cu_code, int use_half, int device_id) {
extern "C" int Compile(const char* ptx_file_name, const char* cu_code, int use_half, int device_id) {

char *ptx;

Expand Down Expand Up @@ -100,7 +101,7 @@ extern "C" __host__ int Compile(const char* ptx_file_name, const char* cu_code,


template < typename TYPE >
__host__ int launch_keops(const char* ptx_file_name, int tagHostDevice, int dimY, int nx, int ny,
int launch_keops(const char* ptx_file_name, int tagHostDevice, int dimY, int nx, int ny,
int device_id, int tagI, int tagZero, int use_half,
int tag1D2D, int dimred,
int cuda_block_size, int use_chunk_mode,
Expand Down Expand Up @@ -337,7 +338,7 @@ __host__ int launch_keops(const char* ptx_file_name, int tagHostDevice, int dimY



extern "C" __host__ int launch_keops_float(const char* ptx_file_name, int tagHostDevice, int dimY, int nx, int ny,
extern "C" int launch_keops_float(const char* ptx_file_name, int tagHostDevice, int dimY, int nx, int ny,
int device_id, int tagI, int tagZero, int use_half,
int tag1D2D, int dimred,
int cuda_block_size, int use_chunk_mode,
Expand Down Expand Up @@ -370,7 +371,7 @@ extern "C" __host__ int launch_keops_float(const char* ptx_file_name, int tagHos



extern "C" __host__ int launch_keops_double(const char* ptx_file_name, int tagHostDevice, int dimY, int nx, int ny,
extern "C" int launch_keops_double(const char* ptx_file_name, int tagHostDevice, int dimY, int nx, int ny,
int device_id, int tagI, int tagZero, int use_half,
int tag1D2D, int dimred,
int cuda_block_size, int use_chunk_mode,
Expand Down Expand Up @@ -402,7 +403,7 @@ extern "C" __host__ int launch_keops_double(const char* ptx_file_name, int tagHo



extern "C" __host__ int launch_keops_half(const char* ptx_file_name, int tagHostDevice, int dimY, int nx, int ny,
extern "C" int launch_keops_half(const char* ptx_file_name, int tagHostDevice, int dimY, int nx, int ny,
int device_id, int tagI, int tagZero, int use_half,
int tag1D2D, int dimred,
int cuda_block_size, int use_chunk_mode,
Expand Down
14 changes: 13 additions & 1 deletion keops/python_engine/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,28 @@ def get_jit_binary(gpu_props_compile_flags, check_compile=True):
+ os.path.sep
+ "compilation"
+ os.path.sep
+ "keops_nvrtc.cu"
+ "keops_nvrtc.cpp"
)
jit_binary = build_path + "keops_nvrtc.so"
if check_compile and not os.path.exists(jit_binary):
print("[KeOps] Compiling main dll...", flush=True, end="")
bindings_source_dir = base_dir_path + "binders"

# nvcc
flags = "-shared -Xcompiler -fPIC -lnvrtc -lcuda "
flags += gpu_props_compile_flags
# jit_compile_command = f"nvcc -I {bindings_source_dir} {flags} {jit_source_file} -o {jit_binary}"
jit_compile_command = f"nvcc {flags} {jit_source_file} -o {jit_binary}"

# g++
flags = "-L/usr/lib/x86_64-linux-gnu -L/opt/cuda/lib64 -L/opt/cuda/targets/x86_64-linux/lib/ "
flags += "-I/usr/local/cuda-11.0/targets/x86_64-linux/include/ -I/opt/cuda/targets/x86_64-linux/include/ -I/opt/cuda/targets/x86_64-linux/include/ "
flags += "-Wl,-rpath,/usr/lib/x86_64-linux-gnu "
flags += "-shared -fPIC -fpermissive -lcudart -lcuda -lnvrtc "
flags += gpu_props_compile_flags
# jit_compile_command = f"nvcc -I {bindings_source_dir} {flags} {jit_source_file} -o {jit_binary}"
jit_compile_command = f"g++ --verbose {flags} {jit_source_file} -o {jit_binary}"

os.system(jit_compile_command)
print("Done.", flush=True)
return jit_binary
Expand Down

0 comments on commit d8f2d87

Please sign in to comment.