Comments (17)
So just to clarify: you can compile Enoki including its Python bindings using both GCC and Clang? But returning a CUDAArray<float>
from pybind11-bound code does not work?
IMO there are only two possibilities for this:
-
Your project and Enoki were compiled with different settings. You have to be careful about the following: use the same version of Clang or GCC. Second (important!) use the same C++ standard library. When compiling Enoki with clang, it uses -stdlib=libc++, which means that your project also has to use -stdlib=libc++.
-
You did not import the Enoki python module that contains the type you are using. Note that there was a change here for the
refactor
branch: onmaster
, it is enough to writeimport enoki
. On therefactor
branch, you need to write:import enoki.autodiff_cuda
(or cuda_autodiff, I don't remember). Note that all the mathematical functions remain inenoki
, so one would typically do computations as follows:
from enoki.autodiff_cuda import Float32, UInt32, ...
import enoki as ek
x = ek.linspace(Float32, -1, 1, 100)
y = ek.select(x > 0, ek.asin(x), ek.acos(x))
...
from enoki.
In particular, look at ENOKI_CUDA, ENOKI_AUTODIFF, and ENOKI_PYTHON in CMake.
from enoki.
You can compile extensive Python bindings for both, including automatic convertion to PyTorch/NumPy. See the 'refactor' branch which contains considerable additional work to this end. The enoki/python.h
file is only applicable to simple CPU-only arrays.
from enoki.
File "", line 1, in
TypeError: Unable to convert function return value to a Python type! The signature was
(self: xxxx.Render) -> enoki::DiffArray<enoki::CUDAArray >
the c++ code is something like this...
struct Render {
FloatD m_bitmap_d;
Render();
FloatD &run();
const FloatD &run() const { return m_bitmap_d; }
void config_print();
~Render() {};
};
from enoki.
Right. You'll need to load the Enoki python module so that its return value converter knows what to do with these types. So simply run import enoki
in your Python code before calling Render::run
. Let me say again that you will probably get a lot more out of the bindings in the refactor
branch of Enoki. For that branch, you will need to run import enoki.cuda_autodiff
.
from enoki.
And FWIW what enoki/python.h
does is to convert C++ Enoki types into corresponding Python types (NumPy arrays) by copying them. That's not really a good way of interfacing between C++ <-> Python when a GPU is involved and the arrays are potentially very big.
You can also take a look at the following list:
https://pybind11.readthedocs.io/en/stable/advanced/cast/index.html.
The header enoki/python.h
corresponds to variant #3, and in Mitsuba 2 and Enoki's refactor
branch we have now completely switched over to variant #1 for doing conversions.
from enoki.
I tried these code and the problem still occur...
C++:
NAMESPACE_BEGIN(xxxx)
struct Render {
Render();
FloatC run(); // return a FloatC
~Render() {};
};
NAMESPACE_END(xxxx)
// pybind
#include <pybind11/pybind11.h>
#include <pybind11/operators.h>
#include <pybind11/complex.h>
#include <pybind11/functional.h>
#include <pybind11/stl.h>
#include <enoki/python.h>
#include <enoki/stl.h>
#include <enoki/cuda.h>
#include <enoki/autodiff.h>
...
pybind11::class_xxxx::Render(m, "Render")
.def(pybind11::init<>())
.def("run", &xxxx::Render::run);
Python:
import enoki
import xxxx
r = xxxx.Render()
r.run()
TypeError: Unable to convert function return value to a Python type! The signature was
(self: xxxx.Render) -> enoki::CUDAArray
from enoki.
Also there is an error while building the refactor branch
from enoki.
Issue 1: You are likely compiling Enoki & your own project with different compilers (G++ vs Clang, or different versions of them). In this case, pybind11 keeps classes in different namespaces to prevent ABI incompatibilities.
Issue 2: Can you try again with the latest refactor branch?
from enoki.
After running refactor branch:
from enoki.
For Issue one:
both the enoki/master any my project are using gcc-8
the problem still occur..
Here is the cmake .. output for both
from enoki.
Can you give Clang a try?
sudo apt install clang-9 lldb-9 clang-tools-9 clang clangd lldb clang-tools \
libc++abi1-9 libc++abi-9-dev libc++1-9 libc++-9-dev \
from enoki.
I fixed the GCC issue you reported just now. Generally, I would still recommend using Clang. I've run into so many issues with miscompilations with GCC in the last 2 years that I have completely lost trust in it.
from enoki.
ok, also should i write pybind11::module::import("enoki"); in my c++ code?
from enoki.
Yes, that's probably a good idea.
from enoki.
I tried to build both (enoki refactor branch) with clang-9 and still now working...
Cmake output:
c++:
FloatC means:
using FloatC = enoki::CUDAArray<Float>;
Thanks for helping T_T
from enoki.
Thanks, it works
from enoki.
Related Issues (20)
- Force enoki::Array<float, 3> to be 12 bytes HOT 4
- [General question] Figuring out the correct index type for `gather` operations HOT 2
- Double precision for Enoki autodiff (not supported yet) HOT 3
- sign documentation is wrong HOT 1
- Using CUDA backend of Enoki in a multithreaded environment HOT 1
- Difference between this enoki and wjakob/enoki HOT 2
- The behavior of enoki::hsum does not correspond to the documentation HOT 5
- Enoki cannot build on VS2019 16.10 HOT 12
- How to use binary_search overloads in python.
- Python ImportError on Windows with enoki.cuda HOT 2
- build issues: undefined reference to `clock_gettime@GLIBC_2.17'
- AMD GPU code generation? HOT 2
- Runtime dynamic dispatch of functions using Enoki? HOT 1
- SYCL support HOT 1
- Error: zero size memory allocation when calling 'cuda_partition' HOT 1
- Enoki does not generate fma instruction for fmadd with Array<float, 1> and Clang
- using enoki with custom matrix class HOT 1
- simple enoki example does not compile with Intel compiler HOT 1
- Vectorized RNG repeats values with nested arrays
- Installation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from enoki.