-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update complex interface #488
base: main
Are you sure you want to change the base?
Conversation
you can't fix this without an API break, so break API in a visible, and useful manner, and completely remove the same-name C++ wrapper; instead of void volk_32fc_x2_dot_prod_32fc(lv_32fc_t*, const lv_32fc_t*, const lv_32fc_t*, unsigned int) a C++ consumer should be calling volk::dot_prod(const std::vector<std::complex<float>>&,const std::vector<std::complex<float>>&, std::vector<std::complex<float>>&) or void volk::dot_prod(const std::complex<float>*, const std::complex<float>*, std::complex<float>*, unsigned int) we should be generating these wrappers automatically. Ideally, these wrappers wouldn't just be C++ functions, but |
Thanks for your suggestions. I want to update the interface and that'll break the current API. The C++ interface should require However, at the moment, I'm stuck with a more trivial problem. For any interface, we'd need to be able to call a C kernel with an |
1b90608
to
fcef50a
Compare
7b40395
to
c37868e
Compare
At the moment I assume, the updated C API is in good shape. The C++ API update is in a more experimental state. It works with 2 examples. C++ Interface requirements
These requirements result in at least 3 functions. More considerations: Do we want to expose more info?
|
efbbdbb
to
68f97db
Compare
68f97db
to
a926463
Compare
At this point, everything compiles and and all tests pass on most systems with most compilers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good starting point! Let me do some macOS testing to see if this builds for me or not & then I can provide more commentary.
@@ -0,0 +1,3 @@ | |||
gcc -std=c17 -I/home/johannes/src/volk/include -I/home/johannes/src/volk/build/include -L/home/johannes/src/volk/build/lib -x c main.c -o mainvolkgnuc -lm -lvolk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guessing you didn't mean to include this file ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ... guessing you're using this & main.c
and main.cc
as part of the draft for testing purposes, and you'll remove these once the PR is out of draft ... yes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. This is a temporary file I intend to remove as soon as I figured out all the details of how to update the interface.
@jdemel the basic concept of the
and then end with
And for
with these changes, this PR builds on macOS for me. These changes should be broadly correct for modern compilers. |
Thanks @michaelld MacOS passes CI now too. What are your thoughts for the C++ interface? |
Yay! I'll look at the Ubuntu failures too & see if I can work out what's going on there.
I like it, in general. I think it's important for us to offer this interface, since there is a lot of complex math that can be accelerated by appropriately-designed kernels. |
Ah ,... the Ubuntu ones are still working. Looking positive right now, doing |
The Windows failure seems consistent with https://docs.microsoft.com/en-us/cpp/c-runtime-library/complex-math-support?view=msvc-160. Namely, that |
My first idea was to browse through: MSVC STL headers Besides, reading through these MSVC specifics, they basically, once again, state: MSVC supports C89-only and only select later extensions. Thus, requiring C11 excludes MSVC. If we can't fix it, we might be forced to revert to define our own custom structure types. Obviously, that'd be a very unpleasant prospect. |
It's distributed as part of the Universal C Runtime, which comes in the Windows SDK. I haven't found a way of viewing just the header without installing the whole thing on a Windows machine, but that's a place to start. |
@ryanvolz Thanks for the hints where to search! typedef struct _C_float_complex
{
float _Val[2];
} _C_float_complex;
typedef _C_float_complex _Fcomplex; Thus, we should be able to do things like: typedef _Fcomplex lv_32fc_t;
typedef _Dcomplex lv_64fc_t; However, we might be forced to define these structs manually. typedef char _Complex lv_8sc_t;
typedef short _Complex lv_16sc_t;
typedef long _Complex lv_32sc_t;
typedef long long _Complex lv_64sc_t; In that case, we might be forced to overload complex math functions as well. Thus, whenever one adds a function that uses these types and some complex math functions, we might need to implement these for a new type. However, I assume we'd just do the convert to |
3e42fa5
to
38f7564
Compare
I tried to define typedef _Fcomplex lv_32fc_t; for MSVC, but the CI tells me
There's something wrong. At this point, I need help from someone with such an environment. |
I have figured out the initial problem: Microsoft's
Now I get the following error about multiplication not being defined for the complex types:
I don't know how far down this rabbit hole you want to go, but this seems to point to the next step. |
38f7564
to
5155b43
Compare
Thanks for having a look at it.
So MSVC does not support any of the things we need. Currently, my idea would be: Use Clang to compile VOLK with MSVC ABI compat and use MSVC to compile tests, volk_profile etc. Since VOLK is effectively a C++ library for MSVC users, that wouldn't exclude anyone. I'm open to suggestions. Also, the current state with a widely used C compiler that is effectively C89 with some random improvements is really unsatisfactory. |
From my conda perspective, using Clang to compile VOLK shouldn't be a problem, although I haven't tried it and I am not aware of the full implications of doing that for downstream consumers (i.e. GNU Radio). |
I don't have any experience with that approach. |
5155b43
to
745afd5
Compare
This is a first try at moving to a sane, defined complex API. Before we were basically relying on undefined behavior. This bites us with PowerPC. The current changes work for C but C++ code does not compile yet. Signed-off-by: Johannes Demel <[email protected]>
Signed-off-by: Johannes Demel <[email protected]>
Signed-off-by: Johannes Demel <[email protected]>
Signed-off-by: Johannes Demel <[email protected]>
With this commit, our QA code should work again. However, it still relies on C types in the C++ domain. We probably want to add a C++ wrapper around C VOLK. The idea: - add `volk.hh` - Include C++ magic in here. - Find idiomatic, modern C++ interface defition. Signed-off-by: Johannes Demel <[email protected]>
Signed-off-by: Johannes Demel <[email protected]>
Signed-off-by: Johannes Demel <[email protected]>
We removed these tests because of our broken interface. Now, we aim to fix this issue and thus, expect it to work again. Signed-off-by: Johannes Demel <[email protected]>
The VOLK C API should be in place. We stick with the current API. Except, we always require it to be C. No more C and C++ mix and match. This allows us to be more open about the C++ API. Here, we write wrappers around our C functions. Signed-off-by: Johannes Demel <[email protected]>
Now we declare extern C for all compilers and hope this works. Signed-off-by: Johannes Demel <[email protected]>
Make sure everything that is supposed have C-linkage does have C-linkage. Signed-off-by: Johannes Demel <[email protected]>
Use `__VOLK_DECL_BEGIN` etc. again. It seems to work now. Signed-off-by: Johannes Demel <[email protected]>
`main.c`, `main.cc` and `compile.sh` are temporary files that are supposed to be removed, once the new interface is stabilized. In order to remove distractions, these files should follow best practices. Signed-off-by: Johannes Demel <[email protected]>
Michael's comments to fix MacOS builds are included now. It compiles on my system too. Hopefully CI etc. passes too. Signed-off-by: Johannes Demel <[email protected]>
MSVC does not support C complex numbers. There's a different approach here. Thus, we try to fix it with some additional burden. Let's poke the CI. Signed-off-by: Johannes Demel <[email protected]>
MSVC requires special treatment. We check for it now. Signed-off-by: Johannes Demel <[email protected]>
It is difficult to get MSVC to compile with complex numbers. Add more referenceses to sources that explain the reasons. Signed-off-by: Johannes Demel <[email protected]>
745afd5
to
9011ff8
Compare
With VOLK 3.1 we went the temporary route to pass complex values by pointer exclusively. While this is not the nicest solution, it works. |
This is a draft.
API break: This work breaks the API on purpose.
Mostly, it is a try to fix these issues with C vs. C++ complex types. We rely on undefined behavior. This is supposed to end and be better.
Apparently, we hit a bunch of issues:
complex
is considered a "niche"complex.h
andstd::complex
seem to be explicitly binary incompatible. At least they're allowed to.char _Complex
.EDIT
Fixes #442
Fixes #572
Current state:
EDIT
Since we want to support compilers that are difficult to support with complex C (i.e. complex C support is missing), we ended up with the current API that basically relies on Undefined Behavior (UB).