We write AI for Vindinium on single-board computers. Part 1: Selection of Candidates

Sometimes there is a desire to distract from the vanity of the world and do something interesting. In my case, it was Vindinium — an AI competition in which four knights fight for fame, wealth, and food.







And prepare yourself a task - to get to the leaderboard. However, the task will be solved even more interestingly if we set a hard limit - artificial intelligence will not draw resources from our undoubtedly powerful computer, but from the single-board system on the ARM architecture! At the same time, we will not only gain experience with portable devices, but also the opportunity to keep the bot turned on 24/7 without any damage to the main computer!



Part 2

Part 3

Let's get started!



Long or short, three single-board computers with a cheap price were found - Orange Pi Zero, NanoPi Neo, NanoPi Neo2, their brief characteristics are presented in the table:

Orange pi zero NanoPi Neo NanoPi Neo2
RAM size 512MB DDR3 512MB DDR3 512MB DDR3
Internal memory - - -
CPU Allwinner H2 + Cortex A7 (32-bit architecture, 4 cores, frequency up to 1200Hz) Allwinner H3 Cortex A7 (32-bit architecture, 4 cores, frequency up to 1200Hz) Allwinner H5 Cortex-A53 ( 64- bit architecture, 4 cores, frequency up to 1500Hz )
Graphics core ARM Mali400 MP2, without a hint of OpenCL ARM Mali400 MP4, without a hint of OpenCL ARM Mali450 MP4, without a hint of OpenCL
"Three sizes", mm 52x46x17 40x40x17 40x40x17
Internet access 100Mbps Ethernet + 802.11 b / g / n WiFi with antenna 100Mbps Ethernet 1Gbps Ethernet
Number of USB outputs 1 (+2 displayed) 1 (+2 displayed) 1 (+2 displayed)
Price (+ delivery to Moscow), $ 7 + 3.85 = 10.85 8 + 5 = 13 15 + 5 = 20


Delivery of Orange Pi Zero took exactly 20 days, Neo and Neo2 came a day earlier, I believe, very quickly.



Let's start to understand ...



Unpacking Parcels ...
image

image

image

image

image

image

image



It is worth saying that the Basic Starter Kit (+13 dollars) was ordered for Neo, which, in addition to the computer, includes:



- USB-to-UART converter;

- large (if you can call an aluminum plate the size of a computer such) radiator + mount;

- MicroSD card for 8GB SanDisk 10class.

- MicroUSB cable.



There is also the Complete Starter Kit ($ 29 + shipping), it includes everything that is in Basic, plus the case and the OLED screen, but for our purpose it is somewhat unnecessary.



Prepare for the first launch ...





From the armbian site we download three fresh images for NanoPi Neo, Neo2 and OrangePi Zero, we will use the MicroSD card obtained from the Basic Starter Kit.



From now on, the single-board computer will be referred to as the single-board computer, and the computer - the usual for us large and powerful computer or laptop.



Now we have two ways with which you can work with single-board devices:



[1] Via Ethernet;



Brief instruction
  1. We connect a single-board through an Ethernet cable to a laptop, computer or router;
  2. We turn on the power for the single board;
  3. We scan the network; for most linux-based systems, you can do this using the “arp -a” command; for Windows, nmap exists;
  4. Connect to the single-server, for linux: “ssh ip -l root”, default password “1234”; in Windows, you can use any ssh client, for example, multifunctional putty




[2] Using USB-to-UART converter.



Brief instruction
  1. We connect the converter to the computer, we define its physical address: in linux we look at the last lines of the command “dmesg | grep tty "and look for something similar to ttyUSBX, for Windows we look in the Device Manager new COM devices
  2. We connect a single-board device to the converter: we connect the wire to the converter so that GND is connected with a black wire and TX is connected with yellow, then we connect a single-board device (Neo / Neo2 are connected to the single unsoldered contacts near the USB port, so that the black wire is near the nearest edge, and yellow pointed in the direction of the flash card, it turns out the order: GND, 5V, RX, TX; Orange Pi Zero cannot be connected with the cable supplied in the Starter Pack, there is no 5V in the middle, so you will have to use another cable)
  3. Now you need to find a program in which it will be convenient to work with the console via TTY / COM: for linux, I will advise a convenient minicom or putty (you need to run as root), for Windows, putty is still relevant




You need to monitor the temperature, you need to monitor the temperature ...



We need to control the temperature if we want to keep an AI for Vindinium on it, avoiding lowering the frequency, freezing, or the failure of a single board. Let's write a simple script for temperature monitoring (at the same time, let's practice running .py files):



Script
import time, sys print('NanoTemp 0.1') while True: with open('/sys/devices/virtual/thermal/thermal_zone0/temp', 'r') as f: temp1 = f.read()[:-1] with open('/sys/devices/virtual/thermal/thermal_zone1/temp', 'r') as f: temp2 = f.read()[:-1] print('\r'+temp1+' '+ temp2) time.sleep(0.5)
      
      







Now you can upload this file on a flashcard in the directory / home / username /.



TIP: Ubuntu, Debian, and many other Linux-based operating systems can work with ext3 / ext4 file systems from under the box; Windows will offer to format the USB flash drive. You need to use tools that allow you to work with this kind of file systems, for example, install the Ext2Fsd driver.



Later, I learned about a program such as armbianmonitor, with which you can safely monitor not only the temperature, but also the frequency, local time and load, which is undoubtedly useful.



Let's connect each odnoplatnik to the power supply, wait 15 minutes in idle time and see the results:

Orange pi zero NanoPi Neo NanoPi Neo2
60 ° C 35 ° C 50.3 ° C


Interestingly enough, the sensor on Neo2 shows the temperature down to the first decimal point, but it hides information about the current processor frequency from us .



It is sad that the Orange Pi Zero is so hot in idle, unlike his brother Neo at the same frequency of 240 MHz. Forums are dotted with discontent on this topic. As an option that solves this problem, a special script is offered, editing system files and using cooling. However, there is also information that these were all measures against heating up to 80 degrees in idle time, and 55-60 degrees in the fresh version of armbian is normal in this case. Apparently, the problem is solved only partially .



Let's try to install passive cooling. For Orange Pi Zero, a special set of two radiators for the processor and RAM was bought for $ 2.82. In the case of the NanoPi, we have a powerful radiator, which can be purchased separately from the Starter Pack for $ 2.99.



Now the picture 15 minutes after launch looks like this:

Orange pi zero NanoPi Neo NanoPi Neo2
53 ° C 30 ° C 39.5 ° C


Warm up in full!



It was observed that the orange was very warm. Interestingly, how many degrees will the temperature jump during loading. We will use the cpuburn program available in the repositories (for Neo and Zero we will use the burnCortexA7 command, for Neo2 we will use the burnCortexA8).



Well say ...



All single-board devices easily reach temperatures of 80 degrees with four instances of cpuburn - passive cooling simply does not cope with such heating. However, I believe that in the case of Vindinium, not everything will be so sad - there is a cyclic change in the phase of work and idle time (waiting for a response from the server), and the cpuburn program itself is designed for the most efficient heat dissipation, the AI ​​cannot load the processor as much minimum because of the need to wait for data from the RAM, because our task will not be able to fully accommodate the processor cache.



However, an interesting feature comes out here - the Orange Pi Zero reaches 80 degrees even with a single copy of cpuburn, for Neo2 three copies are enough, and Neo - four copies of the test.



Benchmarks, people demand bread and benchmarks!



Before you write an AI, you need to determine the most important question: how many times are these monolayers weaker than ordinary computers? I can not believe that a small piece of silicon, metal and PCB can do anything out of the ordinary.



For benchmarking phoronix-test-suite utility was used.



In contrast to all the single-board users, let me allow my laptop to be included in testing (i5 2450M, 6gb DDR3, without discrete graphics, running Ubuntu 16.04 LTS), to facilitate the development of AI (you can run certain pieces of code and know how much, approximately, time will change while working on the same piece on single board). We use only passive cooling. Per unit of productivity we take an orange.



Test description
John The Ripper is a brute force password cracking program. Learn more about the Blowfish cryptographic algorithm used in the test ;

Smallpt is a global illumination renderer consisting of 99 lines in C ++.

C-Ray - CPU performance test in floating point operations. This test is multi-threaded (16 threads per core), will shoot 8 rays from each pixel for smoothing and generate an image of 1600x1200.

The Himeno test is a linear Poisson pressure solver using the Jacobi method .

Built-in 7zip file compression benchmark .

Benchmark using ffmpeg is to encode video and audio .



UPD: while the article was moderated, an old computer was found near the house ( Intel Pentium 4 (1 core, 2 threads, 2003, pre-stub processor on its architecture), 512MB DDR x2, Radeon 9600XT 128MB DDR), thirteen years ago this system can be was called strong. In order to compare how it is, I installed Windows 10 Ubuntu 16.04 LTS, which, to my surprise, turned out to be very efficient.

A laptop Dinosaur computer Orange pi zero NanoPi Neo NanoPi Neo2
John The Ripper 1.8.0, Test: Blowfish (parrots / sec) 797 Real C / S (+ 125%) 313 Real C / S (+ 125%) 354 Real C / S 394 Real C / S (+ 11%) 475 Real C / S (+ 34%)
Smallpt V1.0.2 (seconds) 586 Seconds (4.6 times faster) 1214 Seconds (2.2 times faster) 2694 Seconds 2240 Seconds (1.2 times faster) 1289 Seconds (2.08 times faster)
C-Ray v1.1 (seconds) 120.86 Seconds (5.03 times faster) 294.61 Seconds (2.37 times faster) 607.83 Seconds 485.71 Seconds (1.25 times faster) 349.51 Seconds (1.74 times faster)
Himeno Benchmark v3.0 (parrots) 1165.11 MFLOPS (+ 8908%) 385.28 MFLOPS (+ 2455%) 15.08 MFLOPS 13.08 MFLOPS (15% weaker) 37.23 MFLOPS (+ 185%)
ompress 7zip (parrots) 5010 MIPS (+ 585%, large deviation from the average: 22.77%) 1706 MIPS (+ 88%) 857 MIPS 950 MIPS (+ 11%) 1103 MIPS (+ 29%)
ffmpeg (seconds) 30.69 Seconds (13.25 times faster) 81.22 Seconds (5 times faster) 406.76 Seconds 426.94 Seconds (5% slower) Test failed to run - compile error
Cost including delivery and radiators $ 283.39 (+ 2046%) - $ 13.67 $ 15.97 (+ 17%) $ 22.97 (+ 68%)


When studying information on the Internet, it became clear that H2 + is a slightly modified version of H3 :

H2 + is a variant of H3, designed for low- capacity OTT blocks, in which there is no support for Gigabit MAC and 4K HDMI.


Original:

H2 + is a variant of H3 boxes that are targeted at low-end OTT boxes, and there is no need for Gigabit MAC and 4K HDMI output support.


In this case, it becomes interesting for what reason there is such a difference in performance and thermal conditions between H2 + and H3.



Summarizing.



Having compared three different single-board apps, I can summarize:





For myself, I decided to continue to work with Neo and Neo2, and to put off an orange until some interesting idea about a smart house appears, because Neo's performance is very much like Zero, but without any problems with temperature.



In the next article we will choose a new programming language, which can be learned as soon as the AI ​​is written.



→ Link to Vindinium

→ Link to Vindinium sabreddit - a very useful thing, there you can track my movements on Vindinium

→ Link to my githab with some insights on Vindinium



I would be very pleased if more people pull themselves to this game, because during the rivalry the most interesting begins!



All Articles