artyom-beilis / pytorch_dlprim

DLPrimitives/OpenCL out of tree backend for pytorch
http://blog.dlprimitives.org/
MIT License
286 stars 17 forks source link

Pytorch 2.0 and greater #35

Open apcameron opened 1 year ago

apcameron commented 1 year ago

Can this be used with Pytorch 2.0 and greater and if so what is the process to use it.

This is what I see when I try to build it.

cmake -DCMAKE_PREFIX_PATH=$VIRTUAL_ENV/lib/python3.11/site-packages/torch/share/cmake/Torch .. -- Caffe2: Found gflags with new-style gflags target. -- Caffe2: Found glog with new-style glog target. -- Caffe2: Found protobuf with new-style protobuf targets. -- Caffe2: Protobuf version 3.21.9 === Status === OpenCL: include /usr/include lib /usr/lib64/libOpenCL.so Python: /home/andrew/Downloads/pytorch/env/bin/python3 BLAS: None HDF5: None Sqlite3: include /usr/include lib /usr/lib64/libsqlite3.so Protobuf (onnx): disabled Python dlprim: disabled -- Configuring done (0.2s) CMake Error in CMakeLists.txt: Imported target "torch" includes non-existent path

"/usr/include/torch/csrc/api/include"

in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:

-- Generating done (0.0s) CMake Generate step failed. Build files cannot be regenerated correctly. (env) andrew@StarFive ~/Downloads/pytorch/pytorch_dlprim/build $

artyom-beilis commented 1 year ago

Do you succeed to build it with 1.13 or 1.14? I still had no chance to test it against 2.0 (I should thou)

artyom-beilis commented 1 year ago

But I've seen users built against 2.0 before.

apcameron commented 1 year ago

I have not tried an earlier version as 2.0 is what I have installed on my system and it takes several hours compile on my small SBC. My test version of pytorch is installed in venv environment

artyom-beilis commented 1 year ago

Note you don't need to compile pytorch - only the backend.

apcameron commented 1 year ago

I had to compile pytorch for my SBC as there are no builds currently for the RISCV64 platform for download. Are there specific options I need enabled when I compile it for it to work with your software?

apcameron commented 1 year ago

I will try and compile pytorch 1.13.1 and see if that works for me on riscv64 with your code. I will let you know in the next day or so

apcameron commented 1 year ago

@artyom-beilis Unfortunately pytorch 1.13.1 would not compile on my SBC so I am back to pytorch 2.x

I have managed to get further but now it fails with this error below. How do I fix this? ^ /home/andrew/Downloads/pytorch/pytorch_dlprim/src/utils.cpp: In function ‘cl::Buffer ptdlprim::buffer_from_tensor(const at::Tensor&)’: /home/andrew/Downloads/pytorch/pytorch_dlprim/src/utils.cpp:38:18: error: ‘static_cast’ from type ‘const void’ to type ‘cl_mem’ {aka ‘_cl_mem’} casts away qualifiers 38 | cl_mem p=static_cast(tt.getIntrusivePtr()->storage().data()); | ^~~~~~~~~~~~~~~ make[2]: [CMakeFiles/pt_ocl.dir/build.make:160: CMakeFiles/pt_ocl.dir/src/utils.cpp.o] Error 1 make[1]: [CMakeFiles/Makefile2:100: CMakeFiles/pt_ocl.dir/all] Error 2 make: *** [Makefile:136: all] Error 2

GCC Version information (env) andrew@StarFive ~/Downloads/pytorch/pytorch_dlprim/build $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/riscv64-unknown-linux-gnu/12/lto-wrapper Target: riscv64-unknown-linux-gnu Configured with: /var/tmp/portage/sys-devel/gcc-12.3.1_p20230526/work/gcc-12-20230526/configure --host=riscv64-unknown-linux-gnu --build=riscv64-unknown-linux-gnu --prefix=/usr --bindir=/usr/riscv64-unknown-linux-gnu/gcc-bin/12 --includedir=/usr/lib/gcc/riscv64-unknown-linux-gnu/12/include --datadir=/usr/share/gcc-data/riscv64-unknown-linux-gnu/12 --mandir=/usr/share/gcc-data/riscv64-unknown-linux-gnu/12/man --infodir=/usr/share/gcc-data/riscv64-unknown-linux-gnu/12/info --with-gxx-include-dir=/usr/lib/gcc/riscv64-unknown-linux-gnu/12/include/g++-v12 --with-python-dir=/share/gcc-data/riscv64-unknown-linux-gnu/12/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --disable-libunwind-exceptions --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 12.3.1_p20230526 p2' --with-gcc-major-version-only --disable-esp --enable-libstdcxx-time --enable-lto --disable-libstdcxx-pch --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --disable-multilib --disable-fixed-point --with-abi=lp64d --enable-libgomp --disable-libssp --disable-libada --disable-cet --disable-systemtap --disable-valgrind-annotations --disable-vtable-verify --disable-libvtv --without-zstd --without-isl --enable-default-pie --enable-default-ssp Thread model: posix Supported LTO compression algorithms: zlib gcc version 12.3.1 20230526 (Gentoo 12.3.1_p20230526 p2)