Saturday, January 11, 2020

ROCm with Ryzen 2200G

For reference, here is the output from running /opt/rocm/bin/rocminfo on Ryzen 2200G (with vega 8) after installing ROCm:


ROCk module is loaded
userx is member of video group
=====================   
HSA System Attributes   
=====================   
Runtime Version:         1.1
System Timestamp Freq.:  1000.000000MHz
Sig. Max Wait Duration:  18446744073709551615 (0xFFFFFFFFFFFFFFFF) (timestamp count)
Machine Model:           LARGE                             
System Endianness:       LITTLE                            

==========              
HSA Agents              
==========              
*******                 
Agent 1                 
*******                 
  Name:                    AMD Ryzen 3 2200G with Radeon Vega Graphics
  Marketing Name:          AMD Ryzen 3 2200G with Radeon Vega Graphics
  Vendor Name:             CPU                               
  Feature:                 None specified                    
  Profile:                 FULL_PROFILE                      
  Float Round Mode:        NEAR                              
  Max Queue Number:        0(0x0)                            
  Queue Min Size:          0(0x0)                            
  Queue Max Size:          0(0x0)                            
  Queue Type:              MULTI                             
  Node:                    0                                 
  Device Type:             CPU                               
  Cache Info:             
    L1:                      32(0x20) KB                       
  Chip ID:                 5597(0x15dd)                      
  Cacheline Size:          64(0x40)                          
  Max Clock Freq. (MHz):   3500                              
  BDFID:                   1792                              
  Internal Node ID:        0                                 
  Compute Unit:            4                                 
  SIMDs per CU:            4                                 
  Shader Engines:          1                                 
  Shader Arrs. per Eng.:   1                                 
  WatchPts on Addr. Ranges:4                                 
  Features:                None
  Pool Info:              
    Pool 1                  
      Segment:                 GLOBAL; FLAGS: KERNARG, FINE GRAINED
      Size:                    16776832(0xfffe80) KB             
      Allocatable:             TRUE                              
      Alloc Granule:           4KB                               
      Alloc Alignment:         4KB                               
      Acessible by all:        TRUE                              
  ISA Info:               
    N/A                     
*******                 
Agent 2                 
*******                 
  Name:                    gfx902                            
  Marketing Name:          AMD Ryzen 3 2200G with Radeon Vega Graphics
  Vendor Name:             AMD                               
  Feature:                 KERNEL_DISPATCH                   
  Profile:                 FULL_PROFILE                      
  Float Round Mode:        NEAR                              
  Max Queue Number:        128(0x80)                         
  Queue Min Size:          4096(0x1000)                      
  Queue Max Size:          131072(0x20000)                   
  Queue Type:              MULTI                             
  Node:                    0                                 
  Device Type:             GPU                               
  Cache Info:             
    L1:                      16(0x10) KB                       
  Chip ID:                 5597(0x15dd)                      
  Cacheline Size:          64(0x40)                          
  Max Clock Freq. (MHz):   1100                              
  BDFID:                   1792                              
  Internal Node ID:        0                                 
  Compute Unit:            11                                
  SIMDs per CU:            4                                 
  Shader Engines:          1                                 
  Shader Arrs. per Eng.:   1                                 
  WatchPts on Addr. Ranges:4                                 
  Features:                KERNEL_DISPATCH
  Fast F16 Operation:      FALSE                             
  Wavefront Size:          64(0x40)                          
  Workgroup Max Size:      1024(0x400)                       
  Workgroup Max Size per Dimension:
    x                        1024(0x400)                       
    y                        1024(0x400)                       
    z                        1024(0x400)                       
  Max Waves Per CU:        160(0xa0)                         
  Max Work-item Per CU:    10240(0x2800)                     
  Grid Max Size:           4294967295(0xffffffff)            
  Grid Max Size per Dimension:
    x                        4294967295(0xffffffff)            
    y                        4294967295(0xffffffff)            
    z                        4294967295(0xffffffff)            
  Max fbarriers/Workgrp:   32                                
  Pool Info:              
    Pool 1                  
      Segment:                 GROUP                             
      Size:                    64(0x40) KB                       
      Allocatable:             FALSE                             
      Alloc Granule:           0KB                               
      Alloc Alignment:         0KB                               
      Acessible by all:        FALSE                             
  ISA Info:               
    ISA 1                   
      Name:                    amdgcn-amd-amdhsa--gfx902+xnack   
      Machine Models:          HSA_MACHINE_MODEL_LARGE           
      Profiles:                HSA_PROFILE_BASE                  
      Default Rounding Mode:   NEAR                              
      Default Rounding Mode:   NEAR                              
      Fast f16:                TRUE                              
      Workgroup Max Size:      1024(0x400)                       
      Workgroup Max Size per Dimension:
        x                        1024(0x400)                       
        y                        1024(0x400)                       
        z                        1024(0x400)                       
      Grid Max Size:           4294967295(0xffffffff)            
      Grid Max Size per Dimension:
        x                        4294967295(0xffffffff)            
        y                        4294967295(0xffffffff)            
        z                        4294967295(0xffffffff)            
      FBarrier Max Size:       32                                
*** Done ***


Output from clinfo:


> /opt/rocm/opencl/bin/x86_64/clinfo
Number of platforms:                             1
  Platform Profile:                              FULL_PROFILE
  Platform Version:                              OpenCL 2.1 AMD-APP (3052.0)
  Platform Name:                                 AMD Accelerated Parallel Processing
  Platform Vendor:                               Advanced Micro Devices, Inc.
  Platform Extensions:                           cl_khr_icd cl_amd_event_callback cl_amd_offline_devices


  Platform Name:                                 AMD Accelerated Parallel Processing
Number of devices:                               1
  Device Type:                                   CL_DEVICE_TYPE_GPU
  Vendor ID:                                     1002h
  Board name:                                    AMD Ryzen 3 2200G with Radeon Vega Graphics
  Device Topology:                               PCI[ B#7, D#0, F#0 ]
  Max compute units:                             11
  Max work items dimensions:                     3
    Max work items[0]:                           1024
    Max work items[1]:                           1024
    Max work items[2]:                           1024
  Max work group size:                           256
  Preferred vector width char:                   4
  Preferred vector width short:                  2
  Preferred vector width int:                    1
  Preferred vector width long:                   1
  Preferred vector width float:                  1
  Preferred vector width double:                 1
  Native vector width char:                      4
  Native vector width short:                     2
  Native vector width int:                       1
  Native vector width long:                      1
  Native vector width float:                     1
  Native vector width double:                    1
  Max clock frequency:                           1100Mhz
  Address bits:                                  64
  Max memory allocation:                         6199155916
  Image support:                                 No
  Max size of kernel argument:                   1024
  Alignment (bits) of base address:              1024
  Minimum alignment (bytes) for any datatype:    128
  Single precision floating point capability
    Denorms:                                     Yes
    Quiet NaNs:                                  Yes
    Round to nearest even:                       Yes
    Round to zero:                               Yes
    Round to +ve and infinity:                   Yes
    IEEE754-2008 fused multiply-add:             Yes
  Cache type:                                    Read/Write
  Cache line size:                               64
  Cache size:                                    16384
  Global memory size:                            7293124608
  Constant buffer size:                          6199155916
  Max number of constant args:                   8
  Local memory type:                             Scratchpad
  Local memory size:                             65536
  Max pipe arguments:                            16
  Max pipe active reservations:                  16
  Max pipe packet size:                          1904188620
  Max global variable size:                      6199155916
  Max global variable preferred total size:      7293124608
  Max read/write image args:                     0
  Max on device events:                          1024
  Queue on device max size:                      8388608
  Max on device queues:                          1
  Queue on device preferred size:                262144
  SVM capabilities:                             
    Coarse grain buffer:                         Yes
    Fine grain buffer:                           Yes
    Fine grain system:                           Yes
    Atomics:                                     No
  Preferred platform atomic alignment:           0
  Preferred global atomic alignment:             0
  Preferred local atomic alignment:              0
  Kernel Preferred work group size multiple:     64
  Error correction support:                      0
  Unified memory for Host and Device:            1
  Profiling timer resolution:                    1
  Device endianess:                              Little
  Available:                                     Yes
  Compiler available:                            Yes
  Execution capabilities:                               
    Execute OpenCL kernels:                      Yes
    Execute native function:                     No
  Queue on Host properties:                             
    Out-of-Order:                                No
    Profiling :                                  Yes
  Queue on Device properties:                           
    Out-of-Order:                                Yes
    Profiling :                                  Yes
  Platform ID:                                   0x7fc5670b6d50
  Name:                                          gfx902+xnack
  Vendor:                                        Advanced Micro Devices, Inc.
  Device OpenCL C version:                       OpenCL C 2.0
  Driver version:                                3052.0 (HSA1.1,LC)
  Profile:                                       FULL_PROFILE
  Version:                                       OpenCL 2.0
  Extensions:                                    cl_khr_fp64 cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_3d_image_writes cl_khr_byte_addressable_store cl_khr_fp16 cl_khr_gl_sharing cl_amd_device_attribute_query cl_amd_media_ops cl_amd_media_ops2 cl_khr_image2d_from_buffer cl_khr_subgroups cl_khr_depth_images cl_amd_copy_buffer_p2p cl_amd_assembly_program



Wednesday, November 13, 2019

Compiling cloudflared for armv6

I have a Raspberry Pi 1 running pi-hole for ads filtering.  Recently I tried to configure it to use Cloudflare DNS-over-https but it isn't stable.  Not to mention that the latest "official" release of cloudflared is broken for Raspberry Pi.  So here are the steps to compile it on Raspberry Pi (Note that the build process will take 30+ minutes on RPi.  So you may want to cross-compile it on a PC instead.  Just change the env variable CGO_ENABLED to 0 in the build script.  It only takes a few seconds to compile on my Ryzen 2200G.  Compiling it on RPi is just for fun).

Preparation


We need golang 1.12 or later to compile cloudflared.  But the official go version on Raspbian is 1.7.  Use this to download golang 1.12.  Extract the content and take note of the path.

wget https://storage.googleapis.com/golang/go1.12.linux-armv6l.tar.gz

Also, the build process needs more than 1GB of memory.  You may want to create a temporary swap file:

sudo fallocate -l 1G swapfile
sudo chmod 600 swapfile
sudo mkswap swapfile
sudo swapon swapfile


After building cloudflared, you can use "swapoff" to remove the temporary swap space and then delete the physical file.

Compiling

Here is the script to compile the cloudflared binary.  Save and run it under a working folder.  Edit the definition of the first two variables to point to the golang version you are using and the cloudflared version to compile.  If you are corss-compiling, change the "CC" environment to the cross compiler.

#!/bin/sh
set -e

# custom install version of go >= 1.12
GOLANG_PATH=$HOME/apps/go/bin
# which version to build
CLOUDFLARED_VERSION=2019.11.0

export GOPATH=$(pwd)
export GOOS=linux
export GOARCH=arm
export GOARM=6
export CGO_ENABLED=1
export CC=gcc
export PATH=${GOLANG_PATH}:$PATH
CLOUDFLARED_BUILDTIME=$(date)

go get -v github.com/cloudflare/cloudflared/cmd/cloudflared
cd src/github.com/cloudflare/cloudflared
git checkout tags/${CLOUDFLARED_VERSION}
cd ../../../../

go build -v "-ldflags=-X 'main.Version=${CLOUDFLARED_VERSION}' -X 'main.BuildTime=${CLOUDFLARED_BUILDTIME}'" github.com/cloudflare/cloudflared/cmd/cloudflared


Installation

Follow the instructions on pi-hole web site on how to configure pi-hole to use DNS-over-https

Saturday, May 4, 2019

Building Visual Studio Code on Jetson Nano

Here are the steps for building Visual Studio Code on Nvidia Jetson Nano.

Install nodejs

Visual Studio Code needs node version between 8 and 10. To install node 10 and yarn:

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

sudo apt-get install -y nodejs

curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

sudo apt-get update && sudo apt-get install yarn


Install libraries 

We also need some libraries:

sudo apt-get install libx11-dev libxkbfile-dev libsecret-1-dev 


Clone and build Visual Studio Code

In a working directory, clone the source code and build.

git clone https://github.com/microsoft/vscode

cd vscode

scripts/npm.sh install


Edit 2019-06-15: To enable extensions, edit the product.json file and add the following:

"extensionsGallery": {
  "serviceUrl": "https://marketplace.visualstudio.com/_apis/public/gallery",
  "cacheUrl": "https://vscode.blob.core.windows.net/gallery/index",
  "itemUrl": "https://marketplace.visualstudio.com/items"
}


To run Visual Studio Code:

scripts/code.sh

Friday, May 3, 2019

ROCm OpenCL with openSUSE Tumbleweed

EDIT 20200110:
(0) As of 2020-01-05, running "clinfo" with openSUSE Tumbleeweed 20200103 and these  ROCm packages will cause null pointer dereference errors.
(0) Things are working again with Tumbleeweed 20200108.
(1) The user needs to be member of the "video" group.  Run this command to add yourself to the group "sudo usermod -a -G video $LOGNAME"
(2) The site now has RPM packages for openSUSE.  Go the http://repo.radeon.com/rocm/zyp/zypper/ to download the packages instead.  Also, no need to specify "--nodeps" when installing the packages

- - 8< - - -


With Tumbleweed running Linux kernel 5.0, it is easy to install ROCm OpenCL with upstream kernel.

- Go to http://repo.radeon.com/rocm/zyp/zypper/ and download the latest version of following packages:

hsakmt-roct
hsa-rocr-dev
rocm-opencl
rocm-opencl-devel
rocminfo-1.0.0

(EDIT 20200126) With ROCm 3.0, you also need to install these packages (due to an issue):
comgr
rocm-smi-lib64

- Install them without checking dependencies, assuming you already have libc etc packages installed, e.g.:

sudo rpm -ivh hsakmt-roct-1.0.9-135-g34da614-Linux.rpm hsa-rocr-dev-1.1.9-64-g619177ee-Linux.rpm rocm-opencl-1.2.0-2019040803.x86_64.rpm rocm-opencl-devel-1.2.0-2019040803.x86_64.rpm rocminfo-1.0.0-Linux.rpm

- That's it! Optionally, install clinfo with zypper to check the available platform.  If you have been using Mesa OpenCL, you may want to uninstall it.

Saturday, April 20, 2019

OpenCL hangs with mesa-opencl and Radeon


OpenCL applications (e.g. clinfo and gimp etc) will hang when running under openSUSE Tumbleweed. This is with Mesa-libOpenCL 19.0.1 running on Radeon Sea Islands with amdgpu driver (radeon.cik_support=0 amdgpu.cik_support=1 amdgpu.dc=1).

Seems hitting this same bug.

EDIT: Fixed in Mesa 19.0.3.

Monday, March 25, 2019

NVIDIA Jetson Nano first impression

Just received my NVIDIA Jetson Nano developer kit today.  Here are my first impressions:

- the mounting holes on the board are tiny.  M3 pole won't fit.  The package does come with a paper (!) stand though

- the board is picky on the power supply.  Tried several USB chargers and the board will shutdown during boot.  Ended up using the barrel plug.  Needed to short jumper J48 to enable power supply via the barrel plug.

- during first boot, after configuring the keyboard etc, the machine froze when trying to login.  Needed to recycle the power.

- Need to manually install Tensorflow for python3 (this should install the CUDA accelerated Tensorflow)

- When trying to install scipy with pip3  (compiling from source), the heatsink was too hot to touch and the machine eventually locked up.  Needed to cycle the power to reboot.

- the cpuinfo:

- dmesg:

- lsusb (with keyboard and mouse attached):

- first successful login:


Sunday, February 24, 2019

Windows 7 update error 0x8000FFFF

Just found that my Windows 7 box failed to install the monthly quality rollup since Sep 2018.

There are many discussions on the error code 8000FFFF.  From modifying registry to restarting services.

But in my case, it turns out that the monthly rollups depend on another package KB3177467.  Once manually install KB3177467, the latest monthly rollup can be installed successfully.

Microsoft, please learn to set up dependencies.

Sunday, January 27, 2019

Playing with Google Apps Script

Long time no post!

Here is a little piece of Javascript code that I recently wrote on a Sunday evening.  To be exact, it is a Google Apps Script.

The script processes credit card purchase notifications in my Gmail inbox and logs the data on a Google Sheet.  From there, I could further analyze my spending.

First time using Google Apps Script.  Seems quite powerful and a handy tool for automation.

Sunday, October 7, 2018

A GUI desktop application to read export files from AndSafe

From time to time, there are people contacting me asking about how they can read the export files from AndSafe.

So here it is. A quick hack put together with PyQt5:  https://github.com/kitsook/PyAndSafe.

Monday, June 4, 2018

Measuring film camera shutter speed with Beaglebone Black

Here is a simple circuit utilizing the ADC input on Beaglebone Black to measure camera shutter speed.



A photoresistor is used to detect the light when shutter open, and hence changing the values read by ADC pin P9_40.  The push button is used to trigger the Python script to start reading the ADC input.


Testing on breadboard and the final build on through-hole board:




Note that this is by no mean an accurate measure of absolute shutter speed.  The response time (rise/fall) of photoresistor will affect the result (see the graph below).  Nevertheless, it is useful to compare different shutter speeds.

Source code is available on Github.

Quick start:

git clone https://github.com/kitsook/bbb-adc-measure
cd bbb-adc-measure
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
python adc-measure.py -t 10 > result.csv

Plot the output using gnuplot:

gnuplot
set mxtics 10
set grid
plot 'result.csv' with lines

Here is an example output of measuring 1/15 and 1/8 shutter speeds of my Pentax MX.