Device memory allocation fails on WSL2 - c++

I am trying to run a simple c++ program, with Cuda Thrust functions, on WSL2. It seems that program fails in runtime to allocate device memory. I use Thrust with Microsoft visual studio all the time, and I don’t get any errors.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(proj LANGUAGES CXX CUDA)
add_executable(proj
proj.cu
)
proj.cu:
#include<thrust/host_vector.h>
#include<thrust/device_vector.h>
#include<thrust/fill.h>
int main()
{
//thrust::host_vector<int> h_vec(10);
//thrust::fill(h_vec.begin(), h_vec.end(), 1);
thrust::device_vector<int> d_vec(10);
//thrust::fill(d_vec.begin(), d_vec.end(), 1);
return 1;
}
output:
terminate called after throwing an instance of 'thrust::system::system_error'
what(): get_max_shared_memory_per_block :failed to cudaGetDevice: unknown error
Aborted (core dumped)
If I comment the device_vector line, and use the host vector instead, it runs with no errors.
Additional info:
GeForce GTX 950M
Windows 11 Home. build 22000.51.
WSL2: Ubuntu-18.04
Cuda compilation tools, release 9.1, V9.1.85

Before I post the question, I had already seen the instructions in here , and both downloaded and installed the CUDA driver for WSL, and joined the windows insider program and upgraded to windows 11 build. It did not work though.
But I also had Ubuntu 18.04 installed. I think it was installing Ubuntu 20.4 instead that made the program run without errors in the end!
So, this is what I did to solve this:
-installed Ubuntu 20.04 from Microsoft store (It asked me to download and run a WSL fix first, which I did)
-In powershell, I removed Ubuntu 18.04
wsl --unregister Ubuntu-18.04
Replace Ubuntu-18.04 with the name of your distribution. You can get its name in powershell by
wsl --list
-installed cmake and g++-9 (gcc-9 was already installed)
-downloaded the cuda toolkit using the instructions in here
Then
cmake -DCMAKE_CUDA_COMPILER=/usr/local/cuda-11.0/bin/nvcc ..
make
./proj

Related

How to invoke clang to use current OS GLIBC?

I am building an application in which the application is using GN and ninja to build files. The application is currently building on Ubuntu 20.04 and I am using clang to compile files. But the issue is when I try to build and execute the executable in Ubuntu 18.04, it is giving me this error:-
./application: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by /path/to/lib.so)
So, this basically means that clang is not able to build the files according to the current OS. Is there any flag I need to use to make it work with the current OS? or is there any other to overcome this issue?

Build C++ RTMAPS package on Ubuntu 16.04 & Ubuntu 18.04

I'm working on a C++ project that should support Ubuntu 18 & Ubuntu 16.
I'm actually working on QT (but I'm not sure this is useful information): QT 5.13.2 GCC 64bit
With a C++ compiler: GCC(C++, x86 64bit in /usr/bin)
This project uses a library that I acquired when installing the RTMAPS SDK.
So when I compile it and use it in a PC with Ubuntu 18.04 it works fine. When I try using it in a PC with Ubuntu 16.04 I get the error:
Error: Unable to load package /path/: it was built for another operating system (Ubuntu 18.4)
I have compiled this same project in a Ubuntu 16.04 PC and it runs in the that PC.
Questions:
Is there a way to compile on Ubuntu 18.04 targeting 16.04? (or in general different versions?)
If the library is also a problem, can I just copy paste one generated in Ubuntu 16.04?
Can I have RTMAPS's libraries for both OSs in the smae environement?

Missing file in OpenCV 3.1.0 for Ubuntu 14.04

I am trying to run this code Domain Transform Filter on Ubuntu 14.04. This code has been originally written on Windows 7 Visual studio. When I try to run this code on Ubuntu, I get the error
error: opencv2/core/internal.hpp: No such file or directory
I tried to download this file for Ubuntu but this is specifically related to Windows.
Is there any way to get this file for Ubuntu ?
Install an older OpenCV.
The file is for instance contained in libopencv-core-dev 2.3.1 on Ubuntu 12.04. (So it is not related to Windows.)
If that is not an option, you probably need to correct your existing code for OpenCV 3.

"Cannot execute binary file" when running compiled c++ programs with Eclipse on Ubuntu for Windows platform

I would like to move from Visual Studio on Windows platform to Eclipse on Ubuntu for c++ development, since I develop almost all my programs on Java, with Eclipse, and I just use a Windows virtual machine in order to develop C++ programs for Win OS. So if I would be happy being able to not use Windows VM at all. However, I've managed to configure MinGW and Eclipse successfully enough to compile programs, but not to execute them.
Steps I've gone through so far:
I've installed mingw32 package and dependencies:
$ sudo apt-get install mingw32
I've installed Eclipse Mars for C/C++ development (manually, to keep this installation isolated from other Eclipses I have) and created a new project in this way:
- New C++ project.
- [...]
- Cross-prefix: i586-mingw32msvc-
- Cross path: /usr/bin/
With this configuration I'm able to correctly build a .exe which I can successfully execute on Windows, but when trying to debug it or execute it under Eclipse I get this error: "cannot execute binary file".
Googleing I've seen some posts suggesting to use wine in order to execute the .exe, but I thought mingw32 would be able to execute it. Am I wrong and this is not possible or just doing something wrong?
Mingw32 is a windows compiler, and will compile source to a Windows executable file. Additionally, the compiler cannot execute files (as worded in the question), it just compiles the source code to an executable form, in this case the windows executable (*.exe). So yes, in order to run the .exe in Ubuntu you would need something like Wine which emulates a Windows environment
mingw is a set of GNU tools for building native Windows executables.
It does not execute anything.
If you really want to cross-compile for Windows, you need Windows or an emulator for the execution.
To build for Ubuntu you can just use the native compilers.
sudo apt-get install gcc

"Hello World" fails to run. Eclipse (Galileo) CDT plugin problems with MinGW and Cygwin on Windows Vista

Trying to run a simple Hello World C++ program on Eclipse (Galileo) CDT plugin on Windows Vista. Following the "Before You Begin" instructions for Eclipse/CDT...
1) Downloaded and installed the latest Cygwin. However, could not compile with Cygwin.
Internal Builder: Cannot run program "g++": Launching failed
the Eclipse CDT docs say...
currently Cygwin >= version 3.4.4-999 is not supported since gcc and g++ commands cannot >be launched from the windows' native shell
It seems to be a typo (Cygwin version is at 1.7.7) but running cygcheck -c, I get the version of g++ which is 3.4.4.x.
Hence I assumed that this version of g++ cannot be run from the command line. So gave up on Cygwin.
2) Downloaded and installed MinGW, gdb, MSYS.
This time, it was able to compile, but when trying to run, I get a popup saying that
the program Hello.exe has stopped working
You should use either Cygwin, or Mingw, because their dll's might conflict if they're both discoverable via %PATH%.
Show your build process (copypaste text from your build console) and %PATH% contents.
The simplest solution was to install the latest Eclipse (Helios SR1) and the CDT plugin.
I needed to also delete the old projects/import old source into new projects.
For Galileo, see:
http://sourceware.org/ml/cygwin/2010-03/msg00510.html
http://dreamlayers.blogspot.com/2010/01/eclipse-incompatibility-with-cygwin-17.html