ComputationalRadiationPhysics / student_project_python_bindings

The student project investigates the performance and memory handling of Python bindings for CUDA C++ code created with pybind11.
GNU General Public License v3.0
1 stars 0 forks source link

Memory reference project #27

Closed afif-ishamsyah closed 2 years ago

afif-ishamsyah commented 2 years ago

Mem_ref for CPU numpy is done

SimeonEhrig commented 2 years ago

Where did you test it. Only Windows or also Linux. I get an compiler error, if I try it on Linux.

afif-ishamsyah commented 2 years ago

I only tested it in windows. I will try it on linux

SimeonEhrig commented 2 years ago

Please do this.

afif-ishamsyah commented 2 years ago

I already fixed it. It should work on both linux and windows

SimeonEhrig commented 2 years ago

Please add also some test. Don't need to be to much.

SimeonEhrig commented 2 years ago

I extended the CMakeLists.txt to make CUDA optional. Building the project with CUDA will be enabled with cmake .. -DENABLE_CUDA=ON. All .cu files needs to be renamed to .cpp files. In the CMake files, it is required that the following code is added to each target, which compiles code:

if(TARGET cpyref::cuda)
  target_link_libraries(${_targetName} PUBLIC cpyref::cuda)
  set_cuda_language(${_targetName})
endif()

If the CUDA build is enabled, the the variable ENABLED_CUDA will be defined and can be used in the c++ preprocessor:

#ifdef ENABLED_CUDA
  int cuda_only_variable = 3;
#endif 
SimeonEhrig commented 2 years ago

Please implement also a python_binding, to ask which CPU and GPU types are available. For example, it can return an enum value.

afif-ishamsyah commented 2 years ago

is the python binding will be used to know whether the algorithm we are using is on CPU or GPU? or the type of CPU/GPU? (like intel. amd, nvidia, etc)

and what is best way to implement #ifdef ENABLED_CUDA on python side? is it possible?

SimeonEhrig commented 2 years ago

is the python binding will be used to know whether the algorithm we are using is on CPU or GPU? or the type of CPU/GPU? (like intel. amd, nvidia, etc)

and what is best way to implement #ifdef ENABLED_CUDA on python side? is it possible?

On the python side, you should be able to ask, what is available, e.g.

if len(binding.get_all_acc) == 0:
  raise Error("no acc avaiable")

print("avaiable acc: ")
for acc in binding.get_all_acc:
  print(acc)

if binding.is_cuda_algo:
  algo = binding.CudaAlgo()
elif binding.is_cpu_algo:
  algo = binding.CPUAlgo()

It think, you need to do this via preprocessor defines in the binding.cpp