How to change between GPU mode and CPU mode in caffe? - caffe

I compiled Caffe without copying and editing Makefile.config.example. I tried to run a code in caffe and it shows me CPU mode. My question is that whether it is possible to do refinement on the configuration file after caffe installation? if yes, How?
~/caffe-master$ SOME_COMMANDS BLAH BLAH
CPU mode
How can I switch the running from CPU mode to GPU mode and vice versa?
I really appreciate if you help me. I am beginner in both caffe and python. Thanks

Where are you getting your Caffe? The official BVLC release comes as a GPU build by default.
First, Makefile.config has a pair of lines:
# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1
You have to uncomment this to get a CPU-only build.
Then the final line of each solver file is
solver_mode: GPU
You need to change this to CPU to get CPU execution.

Related

Qemu Virt Machine from flash device image

I have been developing the OS for a prototype device using hardware. Unfortunately, it's a very manual and buggy process to flash the OS each time and then debug the issues.
I'd like to switch to developing the OS in QEMU, so that I can be sure that the OS is loading correctly before going through the faff of programming the device for real. This will come in handy later for Continuous Integration work.
I have a full copy of the NVM device that is generated from my build process. This is a known working image I'd like to run in QEMU as a start point. This is ready to then be JTAG'd onto the device. The partition layout is:
P0 - loader - Flash of IDBLoader from rockchip loader binaries
P1 - Uboot - Flash of Uboot
P2 - trust - Flash of Trust image for rockchip specific loader
P3 - / - Root partition with Debian based image and packages required for application
P4 - data partition - Application Data
I have not changed anything with the Rockchip partitions (P0 - P2) apart from the serial console settings. When trying to boot the image though, nothing happens. There is no output at all, but the VM shows as still running. I use the following command to run it:
qemu-system-aarch64 -machine virt -cpu cortex-a53 \
-kernel u-boot-nodtb.bin \
-drive format=raw,file=image.img \
-boot c -serial stdio
I have no error information to go on to understand what is going on with it, where can I get more information or debug?
QEMU cannot not emulate arbitrary hardware. You will have to compile U-Boot to match the hardware that QEMU emulates, e.g. using make qemu_arm64_defconfig. The OS must also provide drivers for QEMU's emulated hardware.
If you want to emulate the complete hardware to debug drivers, Renode (https://renode.io/) is a good choice.
For anyone else trying to figure this out, I found good resources here:
https://translatedcode.wordpress.com/2017/07/24/installing-debian-on-qemus-64-bit-arm-virt-board/
and
https://azeria-labs.com/emulate-raspberry-pi-with-qemu/
Looking at the information though, you need to extract the kernel from your image and provide that to the qemu command line as an argument. You'll also need to append an argument telling the system which partition to use as a root drive.
My final command line for starting the machine looks like this:
qemu-system-aarch64 -machine virt -cpu cortex-a53 \
-drive format=raw,file=image.img,id=hd \
-boot c -serial stdio
-kernel <kernelextracted> -append "root=fe04"
Different Arm boards can be significantly different from one another in where they put their hardware, including where they put basic hardware required for bootup (UART, RAM, interrupt controller, etc). It is therefore pretty much expected that if you take a piece of low-level software like u-boot or a Linux kernel that was compiled to run on one board and try to run it on a different one that it will fail to boot. Generally it won't be able to output anything because it won't even have been able to find the UART. (Linux kernels can be compiled to be generic and include drivers for a wider variety of hardware, so if you have that sort of kernel it can be booted on a different board type: it will use a device tree blob, provided either by you or autogenerated by QEMU for the 'virt' board, to figure out what hardware it's running on and adapt to it. But kernels compiled for a specific embedded target are often built with only the device drivers they need, and that kind of kernel can't boot on a different system.)
There are broadly speaking two paths you can take:
(1) build the guest for the board you're emulating (here the 'virt' one). u-boot and Linux both have support for QEMU's 'virt' board. This may or may not be useful for what you're trying to do -- you would be able to test any userspace level code that doesn't care what hardware it runs on, but obviously not anything that's specific to the real hardware you're targeting.
(2) In theory you could add emulation support to QEMU for the hardware you're trying to run on. However this is generally a fair amount of work and isn't trivial if you're not already familiar with QEMU internals. I usually ballpark estimate it as "about as much work as it would take to port the kernel to the hardware"; though it depends a bit on how much functionality you/your guest need to have working, and whether QEMU already has a model of the SoC your hardware is using.
To answer the general "what's the best way to debug a guest image that doesn't boot", the best thing is usually to connect an arm-aware gdb to QEMU's gdbstub. This gives you debug access broadly similar to a JTAG debug connection to real hardware and is probably sufficient to let you find out where the guest is crashing. QEMU also has some debug logging options under the '-d' option, although the logging is partially intended to assist in debugging problems within QEMU itself and can be a bit tricky to interpret.

How can I execute a C program on Qemu riscv and observe the output?

What should be the best approach to run a C code in Qemu riscv and observe the output? I installed Qemu riscv following this link.What should I do now?
https://risc-v-getting-started-guide.readthedocs.io/en/latest/linux-qemu.html
You probably want to use the static user mode version of Qemu for most applications.
Then make sure to compile for RISC-V with the -static flag, and call qemu-riscv64-static [executable].
I highly recommend this, the system mode is a massive pain to handle if you don't need it
(have fun debugging the UART).
You can use libriscv to run RISC-V programs: https://github.com/fwsGonzo/libriscv
Inside the emulator folder there are 2 ways to build the emulator. build.sh produces emulators that run programs with no instruction listing. debug.sh produces debugging variant that shows the state of registers and instructions all the way through the program.
Building Qemu from sources is complete overkill.

I have kernel image for Qemu but i dont know for what machine it has configured to emulate? (for example vexpress-a9 or virt .,)

I have kernel image for Qemu but don't know for what machine it has configured to emulate? (for example vexpress-a9 or virt .,)
How do I find the configured machine by using kernel image?
If you have a working QEMU command line that goes with the kernel, you can look at what the -M/--machine option it uses is. Otherwise, if you have the kernel .config you can see which machines the kernel was built with support for. Otherwise, you need to ask whoever it was that built the kernel what they intended it to be used for, or just throw it away and get or build one that you know does work.

How to run Valgrind to find out memory leaks on my Embedded MIPSEL- linux box?

How can I run valgrind on an embedded Linux box to find memory leaks in my main software?
In the rcS script, I am running like this:
./main_app
How can I associate the ./main_app program with valgrind? The main_app process never terminates.
I want to constantly log the data to file. Also, I want to access the log file without terminating the main_app process. I can do telnet and can access the log file. But the problem is until and unless the handler is closed, how can I open the file i.e. I don't quite understand which valgrind parameters control how memory leaks are logged to file. Please help!
You can try to build it by your own for mips, here the steps:
download valgrind from here http://valgrind.org/downloads/ - I used Valgrind 3.8.1
unpack archive with valgrind and move to the valgrinds folder
execute:
./autogen.sh
./configure --host=mipsel-linux-gnu --prefix=/home/pub/valgrind CFLAGS="-mips32r2" CC=/opt/toolchains/mips-4.3/bin/mips-linux-gnu-gcc CXX=/opt/toolchains/mips-4.3/bin/mips-linux-gnu-c++
./make -j6
./make install
prefix - folder to install compiled binaries of valgrind;
CC and CXX - path to compilers;
CFLAGS - "-mips32r2" and "-mplt" flags should be passed to compilers if it older then gcc (GCC) 4.5.1
on target mips box export path to valgrind lib folder:
export VALGRIND_LIB=/mnt/nfs/lib/valgrind
Now you can use it as usual, for memory checking features you can look here http://valgrind.org/docs/manual/mc-manual.html
It works for me, good luck.
Valgrind only works on x86. You can still track down your leak if you build your application for x86 and run it under valgrind there. Its unlikely the problem is specific to the target architecture.
The answer above describes how to build valgrind but to actually get a full leak check as opposed to just a list of memory problems, your program does have to terminate, I am guessing you never terminate your program.
Assuming your process is some kind of daemon process your best bet is just run it in a loop, monitor memory usage using something like top and then when you see signs of excessive memory usage send it a shutdown command somehow. If you then run valgrind with the following options, you will get a unique log for each process run, including a dump of leaks at exit:
while true ; do
valgrind --leak-check=yes --log-file=/tmp/log.%p.txt main_app
sleep 1
done
The %p in the filename inserts the process id.
You can also specify --show-possibly-lost=no which will reduce the volume of leaks reported to those that valgrind has a much higher degree of confidence are lost.

Nsight debugger doesn't go to device functions [duplicate]

I'we been writing some simple cuda program (I'm student so I need to practice), and the thing is I can compile it with nvcc from terminal (using Kubuntu 12.04LTS) and then execute it with optirun ./a.out (hardver is geforce gt 525m on dell inspiron) and everything works fine. The major problem is that I can't do anything from Nsight. When I try to start debug version of code the message is "Launch failed! Binaries not found!". I think it's about running command with optirun but I'm not sure. Any similar experiences? Thanks, for helping in advance folks. :)
As this was the first post I found when searching for "nsight optirun" I just wanted to wanted to write down the steps I took to make it working for me.
Go to Run -> Debug Configurations -> Debugger
Find the textbox for CUDA GDB executable (in my case it was set to "${cuda_bin}/cuda-gdb")
Prepend "optirun --no-xorg", in my case it was then "optirun --no-xorg ${cuda_bin}/cuda-gdb"
The "--no-xorg" option might not be required or even counterproductive if you have an OpenGL window as it prevents any of that to appear. For my scientific code however it is required as it prevents me from running into kernel timeouts.
Happy bug hunting.
We tested Nsight on Optimus systems without optirun - see "Install the cuda toolkit" in CUDA Toolkit Getting Started on using CUDA toolkit on the Optimus system. We have not tried optirun with Nsight EE.
If you still need to use optirun for debugging, you can try making a shell script that uses optirun to start cuda-gdb and set that shell script as cuda-gdb executable in the debug configuration properties.
The simplest thing to do is to run eclipse with optirun, that will also run your app properly.