Skip to content
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

Getting a undefined reference error while creating a Kompute Manager #100

Closed
unexploredtest opened this issue Dec 19, 2020 · 10 comments
Closed

Comments

@unexploredtest
Copy link
Contributor

Sorry if this is a silly problem. I'm just a beginner in c++ and just learned about vulkan kompute.
So, I'm using 'Kompute.hpp' release version v0.5.1, have installed (vulkan-headers)[https://archlinux.org/packages/extra/any/vulkan-headers/] and using g++ compiler (version 10.2.0)
When I try to create a Kompute Manager with the following code:

#include "Kompute.hpp"

int main() {    
    kp::Manager mgr(0);
}

I get this error:

/usr/bin/ld: /tmp/ccBGpMNE.o: in function `main':
welp.cpp:(.text+0xa17): undefined reference to `kp::Manager::Manager(unsigned int, std::vector<unsigned int, std::allocator
/usr/bin/ld: welp.cpp:(.text+0xa35): undefined reference to `kp::Manager::~Manager()'
collect2: error: ld returned 1 exit status

Are there any other information or logs I should share?

@axsaucedo
Copy link
Member

Thank you for trying out Vulkan Kompute @aliPMPAINT - no need to provide further information at this point as the issue is basically that your current build process doesn't link the kompute shared/static library (which is hence why you get an undefined reference). You have various ways of doing this - the easiest way is by using cmake as your build system. There is an end-to-end example that shows you how to do this via the Google Colab notebook, which you can try yourself, and can be found in this section https://github.com/EthicalML/vulkan-kompute#trying-the-colab-notebook.

Let me know if you have any further questions - happy to provide pointers or further links.

@unexploredtest
Copy link
Contributor Author

unexploredtest commented Dec 19, 2020

@axsaucedo Thank you for your response. Sorry for bothering again. I did follow the guide provided on colab but now, I'm facing another issue. after the compilation of example_array_multiplication project, I now get Segmentation fault (core dumped) error:

WARNING: radv is not a conformant vulkan implementation, testing use only.
[2020-12-19 18:41:28.403] [info] [Manager.cpp:257] Using physical device index 0 found AMD RADV VERDE (ACO)
[2020-12-19 18:41:28.415] [info] [Sequence.cpp:74] Kompute Sequence command recording BEGIN
[2020-12-19 18:41:28.416] [info] [Sequence.cpp:99] Kompute Sequence command recording END
[2020-12-19 18:41:28.416] [info] [Sequence.cpp:74] Kompute Sequence command recording BEGIN
[2020-12-19 18:41:28.416] [info] [Sequence.cpp:99] Kompute Sequence command recording END
[2020-12-19 18:41:28.416] [info] [Sequence.cpp:74] Kompute Sequence command recording BEGIN
[2020-12-19 18:41:28.416] [info] [Sequence.cpp:99] Kompute Sequence command recording END
[2020-12-19 18:41:28.416] [info] [Sequence.cpp:74] Kompute Sequence command recording BEGIN
[2020-12-19 18:41:28.416] [info] [OpAlgoBase.cpp:35] Kompute OpAlgoBase dispatch size X: 3, Y: 1, Z: 1
[2020-12-19 18:41:28.416] [warning] [OpAlgoBase.cpp:140] Kompute OpAlgoBase Running shaders directly from spirv file
Segmentation fault (core dumped)

I'm a total beginner, what am I doing wrong?
Here is also my cmake log:

-- The C compiler identification is GNU 10.2.0
-- The CXX compiler identification is GNU 10.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found Vulkan: /lib/libvulkan.so  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alipmpaint/Documents/vulkan-kompute/build

@axsaucedo
Copy link
Member

@aliPMPAINT is this error happening in the Colab when running the cells in order? Or is this after doing further additions/changes in the example?

I can see that from the warning message this may be run in a radeon card, so I assume this is running on your local device. My initial guess woudl be that you may be attempting to read a shader file as a raw string (as opposed to SPIRV bytes) - if this is the case, I suggest for you to convert into SPIRV bytes and read that instead, as it may just be that the underlying libraries required to read from raw strings may be required. Alternatively let me know further details as well as the code you're running to have further insights on the context.

@unexploredtest
Copy link
Contributor Author

unexploredtest commented Dec 19, 2020

@axsaucedo Yeah, I ran it on my local machine and followed the guide. The code I used is the code provided in Colab.

@axsaucedo
Copy link
Member

Ok I see @aliPMPAINT, I believe if you just change this part -DKOMPUTE_SHADER_FROM_STRING=1 to -DKOMPUTE_SHADER_FROM_STRING=0 it should work (and rerun everything from scratch). Could you give it a try?

@unexploredtest
Copy link
Contributor Author

unexploredtest commented Dec 19, 2020

@axsaucedo I do get the same thing. I tried running a (simpler code)[https://github.com/EthicalML/vulkan-kompute#your-first-kompute-simple-version] instead, and got more explicit error outputs while compiling:

make: Entering directory '/home/alipmpaint/Documents/example_array_multiplication/build'
make[1]: Entering directory '/home/alipmpaint/Documents/example_array_multiplication/build'
make[2]: Entering directory '/home/alipmpaint/Documents/example_array_multiplication/build'
Scanning dependencies of target kompute_array_mult
make[2]: Leaving directory '/home/alipmpaint/Documents/example_array_multiplication/build'
make[2]: Entering directory '/home/alipmpaint/Documents/example_array_multiplication/build'
[ 50%] Building CXX object CMakeFiles/kompute_array_mult.dir/src/Main.cpp.o
/home/alipmpaint/Documents/example_array_multiplication/src/Main.cpp: In function 'int main()':
/home/alipmpaint/Documents/example_array_multiplication/src/Main.cpp:16:23: error: 'kp::OpMult' is not a template
   16 |     mgr.evalOpDefault<kp::OpMult<>>(
      |                       ^~
/home/alipmpaint/Documents/example_array_multiplication/src/Main.cpp:24:19: error: 'class std::shared_ptr<kp::Tensor>' has no member named 'data'
   24 |         tensorOut.data()) << std::endl;
      |                   ^~~~
make[2]: *** [CMakeFiles/kompute_array_mult.dir/build.make:82: CMakeFiles/kompute_array_mult.dir/src/Main.cpp.o] Error 1
make[2]: Leaving directory '/home/alipmpaint/Documents/example_array_multiplication/build'
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/kompute_array_mult.dir/all] Error 2
make[1]: Leaving directory '/home/alipmpaint/Documents/example_array_multiplication/build'
make: *** [Makefile:103: all] Error 2
make: Leaving directory '/home/alipmpaint/Documents/example_array_multiplication/build'

Also, I should point out that the python package worked without any flaw.
Maybe the installation went wrong?
EDIT: Sent the wrong output, now changed

@axsaucedo
Copy link
Member

Ok I need to update the example as the OpMult class is no longer a template since v0.5.0 - good catch!

Ok one more ask to try on the same code as before (the Colab example). Could you remove the whole parameter -DKOMPUTE_SHADER_FROM_STRING=0 alltogether? So basically ensure that's not set - looking at the code it seems it just checks whether its set, so changing it to Zero won't do the job. Can you try that and let me know what it looks like?

For complenetess (and context), as you suggest given that the python works it's indeed that your computer doesn't have the shaderc libraries which means that it can't read from raw strings, it has to be directly from spirv.

@axsaucedo
Copy link
Member

As a sidenote I've updated readme docs example via #101

@unexploredtest
Copy link
Contributor Author

unexploredtest commented Dec 19, 2020

@axsaucedo Oh yeah, now it works:

[alipmpaint@archlinux Documents]$ ./example_array_multiplication/build/kompute_array_mult                                                                                     
WARNING: radv is not a conformant vulkan implementation, testing use only.
[2020-12-19 21:55:57.822] [info] [Manager.cpp:257] Using physical device index 0 found AMD RADV VERDE (ACO)
[2020-12-19 21:55:57.833] [info] [Sequence.cpp:74] Kompute Sequence command recording BEGIN
[2020-12-19 21:55:57.834] [info] [Sequence.cpp:99] Kompute Sequence command recording END
[2020-12-19 21:55:57.834] [info] [Sequence.cpp:74] Kompute Sequence command recording BEGIN
[2020-12-19 21:55:57.834] [info] [Sequence.cpp:99] Kompute Sequence command recording END
[2020-12-19 21:55:57.834] [info] [Sequence.cpp:74] Kompute Sequence command recording BEGIN
[2020-12-19 21:55:57.834] [info] [Sequence.cpp:99] Kompute Sequence command recording END
[2020-12-19 21:55:57.834] [info] [Sequence.cpp:74] Kompute Sequence command recording BEGIN
[2020-12-19 21:55:57.834] [info] [OpAlgoBase.cpp:35] Kompute OpAlgoBase dispatch size X: 3, Y: 1, Z: 1
[2020-12-19 21:55:57.834] [warning] [OpAlgoBase.cpp:140] Kompute OpAlgoBase Running shaders directly from spirv file
[2020-12-19 21:55:57.835] [info] [Sequence.cpp:99] Kompute Sequence command recording END
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:74] Kompute Sequence command recording BEGIN
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:99] Kompute Sequence command recording END
===========================================
RESULTS
===========================================
Output: {  0  4  12  }
===========================================
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:221] Freeing CommandBuffer
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:234] Destroying CommandPool
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:248] Kompute Sequence clearing operations buffer
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:221] Freeing CommandBuffer
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:234] Destroying CommandPool
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:248] Kompute Sequence clearing operations buffer
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:221] Freeing CommandBuffer
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:234] Destroying CommandPool
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:248] Kompute Sequence clearing operations buffer
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:221] Freeing CommandBuffer
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:234] Destroying CommandPool
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:248] Kompute Sequence clearing operations buffer
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:221] Freeing CommandBuffer
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:234] Destroying CommandPool
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:248] Kompute Sequence clearing operations buffer
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:31] Kompute Sequence destructor called but sequence is not initialized so no need to removing GPU resources.
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:31] Kompute Sequence destructor called but sequence is not initialized so no need to removing GPU resources.
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:31] Kompute Sequence destructor called but sequence is not initialized so no need to removing GPU resources.
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:31] Kompute Sequence destructor called but sequence is not initialized so no need to removing GPU resources.
[2020-12-19 21:55:57.836] [info] [Sequence.cpp:31] Kompute Sequence destructor called but sequence is not initialized so no need to removing GPU resources.
[2020-12-19 21:55:57.836] [info] [Manager.cpp:72] Destroying device

Thanks you so much and sorry for asking silly questions
Shall I close the issue?

@axsaucedo
Copy link
Member

Great! No worries, at least we also found that the readme needed updating. Yes it seems we can now close the issue :) let me know if any further issues arise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants