Sunday, December 22, 2024

How to run HMA single image super resolution on Windows 11 computer

Prerequisites

Windows 11 PC with 64GB+ memory

Nvidia GPU with 24GB+ VRAM

Setup HMA


Install Cuda 11.8.0 https://developer.nvidia.com/cuda-toolkit-archive
Install cudnn 9.4.0 https://developer.nvidia.com/cudnn-archive

Install miniforge https://github.com/conda-forge/miniforge/releases/download/24.7.1-0/Miniforge3-24.7.1-0-Windows-x86_64.exe

Download HMA zip from https://github.com/korouuuuu/HMA 

   press code → Download ZIP onto C:\work\HMA

Fix bug of C:\work\HMA\hma\data\paired_imagenet_dataset.py according to https://github.com/korouuuuu/HMA/pull/5/files


Run Miniforge prompt and type following commands


conda update -y -n base -c defaults conda

conda update -y --all

cd C:\work\HMA

conda create -y -n HMA python=3.9

conda activate HMA

conda install -y pytorch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 pytorch-cuda=11.8 -c pytorch -c nvidia

 pip install "numpy==1.23.0" "ipython==7.21.0" "opencv-python==4.5.4.58" "einops==0.4.1"

pip install -r requirements.txt

python setup.py develop

          


Download pretrained model file HMA_SRx2_pretrain.pth from

https://drive.google.com/drive/folders/13Bxt_BXtWgwwcO7tjfoL6zYZAUY1v3zi


Save it as

C:\work\HMA\experiments\pretrained_models\HMA_SRx2_pretrain.pth


Dataset preparation


(Dataset used is https://github.com/XPixelGroup/BasicSR/blob/master/docs/DatasetPreparation.md )


Download Set5 Set14 BSD100 Urban100 MANGA109

from https://drive.google.com/drive/folders/1gt5eT293esqY0yr1Anbm36EdnxWW_5oH


Unzip and arrange Set5 Set14 directories as

C:\work\HMA\datasets\Set5\LRbicx2

C:\work\HMA\datasets\Set5\GTmod2 (renamed from GTmod12)

C:\work\HMA\datasets\Set14\LRbicx2

C:\work\HMA\datasets\Set14\GTmod2( renamed from GTmod12)


Edit C:\work\HMA\options\test\HMA_SRx2.yml to delete test_3 test_4 test_5, leave Set5 Set14 as it is


Run test

On the Miniforge prompt

conda activate HMA

python hma/test.py -opt options/test/HMA_SRx2.yml


Suprer-esolution result images are written onto C:\work\HMA\results\HMA_test_X2\visualization


Saturday, September 14, 2024

How to run RealBasicVSR on Windows 11

Prerequisites

Windows 11 PC with 64GB+ memory

Nvidia GPU with 12GB+ VRAM

mp4 video file of short duration (30 seconds or less) as input.mp4

Setup and run RealBasicVSR


Install Cuda 11.8.0 https://developer.nvidia.com/cuda-toolkit-archive
Install cudnn 9.4.0 https://developer.nvidia.com/cudnn-archive

Install miniforge https://github.com/conda-forge/miniforge/releases/download/24.7.1-0/Miniforge3-24.7.1-0-Windows-x86_64.exe

Install Visual Studio 2022 Professional
add C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.41.34120\bin\Hostx64\x64 to environment PATH
(I think it is possible to use Visual Studio 2022 Community edition instead)

Run Miniforge prompt and type following commands


conda update -y -n base -c defaults conda
conda update -y --all

conda env remove -y -n realbasicvsr

conda create -y -n realbasicvsr python=3.9

conda activate  realbasicvsr 

conda install -y pytorch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 pytorch-cuda=11.8 -c pytorch -c nvidia
conda install -y fsspec==2024.9.0 openmim==0.3.7 ninja==1.12.1 albumentations==1.4.14

mim install mmcv==2.1
mim install mmengine==0.10.4
mim install mmagic==1.2.0
conda install -y numpy==1.26
conda install -y platformdirs==4.3.2
conda install -y diffusers==0.28

Download mmagic=1.2.0 as zip https://github.com/open-mmlab/mmagic/archive/refs/tags/v1.2.0.zip
extract it
cd mmagic-1.2.0



python demo/mmagic_inference_demo.py --model-name real_basicvsr --video ./input.mp4 --result-out-dir ./out/out.mp4


It runs. The result is not convincing. Maybe something is wrong.

Tuesday, December 19, 2023

Hilbert Matrix 20x20 LDLT decomposition

 The following is LDLT decomposition of 20x20 Hilbert Matrix. The diagonal matrix contains very small number.

It seems Firefox render this page correctly.

Hilbert Matrix H=[ 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 ]

L=[ 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 3 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 4 9 10 3 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 5 4 5 12 7 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 6 5 7 25 14 25 9 5 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 7 9 14 25 14 10 3 45 11 3 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 8 7 12 7 4 245 66 245 44 147 26 7 2 1 0 0 0 0 0 0 0 0 0 0 0 0 1 9 8 15 56 33 392 99 980 143 112 13 112 15 4 1 0 0 0 0 0 0 0 0 0 0 0 1 10 27 55 18 11 588 143 1134 143 756 65 63 5 162 17 9 2 1 0 0 0 0 0 0 0 0 0 0 1 11 5 11 225 143 600 143 1260 143 189 13 315 17 300 17 225 19 5 1 0 0 0 0 0 0 0 0 0 1 12 11 26 275 182 55 13 495 52 7623 442 847 34 9075 323 1815 76 605 42 11 2 1 0 0 0 0 0 0 0 0 1 13 36 91 132 91 55 13 4455 442 4356 221 10164 323 13068 323 5445 133 220 7 396 23 6 1 0 0 0 0 0 0 0 1 14 13 35 39 28 143 34 715 68 14157 646 61347 1615 122694 2261 16731 266 9295 161 1859 46 507 25 13 2 1 0 0 0 0 0 0 1 15 7 20 91 68 637 153 7007 646 77077 3230 143143 3230 22308 323 39039 437 13013 138 91091 1150 1274 25 637 27 7 1 0 0 0 0 0 1 16 45 136 175 136 15925 3876 28665 2584 33033 1292 65065 1292 1254825 14858 418275 3496 13013 92 63063 460 637 6 2275 36 1575 58 15 2 1 0 0 0 0 1 17 16 51 400 323 3920 969 3640 323 8736 323 416416 7429 743600 7429 66924 437 4576 23 224224 1035 2912 15 36400 261 2240 29 960 31 8 1 0 0 0 1 18 17 57 68 57 680 171 2380 209 12376 437 80444 1311 252824 2185 82654 437 165308 621 330616 1035 420784 1305 210392 783 161840 899 2890 31 1156 33 17 2 1 0 0 1 19 27 95 153 133 816 209 55080 4807 12852 437 723996 10925 286416 2185 495924 2185 165308 483 1487772 3335 360672 725 420784 899 327726 899 78030 341 1224 11 1377 35 9 1 0 1 20 19 70 171 154 969 253 2907 253 17442 575 40698 575 16796 115 214149 805 29838094 70035 29838094 50025 16275324 22475 1356277 1798 6572727 9889 165699 341 110466 385 18411 140 3249 74 19 2 1 ]

D=[ 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 180 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2800 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 44100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 698544 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 11099088 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 176679360 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2815827300 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 44914183600 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 716830370256 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 11445589052352 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 182811491808400 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2920656969720000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 46670906271240000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 745904795339462400 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 11922821963004219300 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 190600129650794094000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 3047248986392325330000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 48722219250572027160000 ]

Hilbert Matrix H= L D L T

Sunday, December 10, 2023

Move constructor and emplace_back for std::vector performance improvement (Native C++)

Performance improvement with move constructor and emplace_back against copy constructor and push_back is very visible: See below program output.

There are many pitfalls in move constructors. Please read the textbook before utilizing it.

BTW, this is just demonstration purpose for the pointer member to contain only one int value. In this particular case, replacing int *p with int  v improves the performance much more,

C++ Program

#include <iostream>
#include <vector>
#include <stdio.h>
#include <map>
using namespace std;

static int PtrToId(const void* p) {
    static int id = 400;
    static map<const void*, int> ptrIdMap;
    auto found = ptrIdMap.find(p);
    if (found != ptrIdMap.end()) {
        return found->second;
    }
    
    ptrIdMap[p] = id;
    id += 8;

    return ptrIdMap[p];
}

class A {
public:
    int *p = nullptr;
    static int newCounter;

    A(void) {
        p = new int;
        ++newCounter;
        *p = 0;
        cout << "Ctor  new this=" << PtrToId(this) << ", p=" << PtrToId(p) << endl;
    }

    A(int d) {
        p = new int;
        ++newCounter;
        *p = d;
        cout << "Ctor(int) this=" << PtrToId(this) << ", p=" << PtrToId(p) << ", *p=" << *p << endl;
    }

    A(const A& rhs) {
        p = new int;
        ++newCounter;
        *p = *(rhs.p);
        cout << "Copy ctor this=" << PtrToId(this) << ", p=" << PtrToId(p) << ", *p=" << *p << endl;
    }

    ~A(void) {
        cout << "Dtor  del this=" << PtrToId(this) << ", p=" << PtrToId(p) << ", *p=" << *p << endl;
        delete p;
        p = nullptr;
    }
};
int A::newCounter = 0;

class B {
public:
    int *p = nullptr;
    static int newCounter;

    B(void) {
        p = new int;
        ++newCounter;
        *p = 0;
        cout << "Ctor  new this=" << PtrToId(this) << ", p=" << PtrToId(p) << endl;
    }

    B(int d) {
        p = new int;
        ++newCounter;
        *p = d;
        cout << "Ctor(int) this=" << PtrToId(this) << ", p=" << PtrToId(p) << ", *p=" << *p << endl;
    };

    B(const B& rhs) {
        p = new int;
        ++newCounter;
        *p = *(rhs.p);
        cout << "Copy ctor this=" << PtrToId(this) << ", p=" << PtrToId(p) << ", *p=" << *p << ", &rhs=" << PtrToId(&rhs) << endl;
    }

    B(B&& rhs) noexcept {
        p = rhs.p;
        rhs.p = nullptr;

        cout << "Move ctor this=" << PtrToId(this) << ", p=" << PtrToId(p) << ", *p=" << *p << ", &rhs=" << PtrToId(&rhs) << endl;
    }

    ~B(void) {
        if (p) {
            cout << "Dtor  del this=" << PtrToId(this) << ", p=" << PtrToId(p) << ", *p=" << *p << endl;
            delete p;
            p = nullptr;
        } else {
            cout << "Dtor      this=" << PtrToId(this) << ", p=nullptr" << endl;
        }
    }
};
int B::newCounter = 0;

template <typename T>
static void Print(vector<T> &v, const char* name)
{
    for (int i = 0; i < v.size(); ++i) {
        printf(" &(%s[%d])=%d, p=%d, *p=%d\n", name, i, PtrToId(&(v[i])), PtrToId(v[i].p), *(v[i].p));
    }
}

int main(void)
{
    {
        printf("vA/push_back Begin\n");
        vector<A> vA;

        printf("push_back(10)\n");
        vA.push_back(10);
        Print(vA, "vA");

        printf("\npush_back(20)\n");
        vA.push_back(20);
        Print(vA, "vA");

        printf("\npush_back(30)\n");
        vA.push_back(30);
        Print(vA, "vA");

        printf("\nvA/push_back end\n");
    }
    printf("new int is called %d times.\n", A::newCounter);
    A::newCounter = 0;

    {
        printf("\nvA/emplace_back Begin\n");
        vector<A> vA;

        printf("emplace_back(10)\n");
        vA.emplace_back(10);
        Print(vA, "vA");

        printf("\nemplace_back(20)\n");
        vA.emplace_back(20);
        Print(vA, "vA");

        printf("\nemplace_back(30)\n");
        vA.emplace_back(30);
        Print(vA, "vA");

        printf("\nvA/emplace_back end\n");
    }
    printf("new int is called %d times.\n", A::newCounter);

    {
        printf("\nvB/push_back begin\n");
        vector<B> vB;

        printf("push_back(10)\n");
        vB.push_back(10);
        Print(vB, "vB");

        printf("\npush_back(20)\n");
        vB.push_back(20);
        Print(vB, "vB");

        printf("\npush_back(30)\n");
        vB.push_back(30);
        Print(vB, "vB");

        printf("\nvB/push_back end\n");
    }
    printf("new int is called %d times.\n", B::newCounter);

    B::newCounter = 0;
    {
        printf("\nvB/emplace_back begin\n");
        vector<B> vB;

        printf("emplace_back(10)\n");
        vB.emplace_back(10);
        Print(vB, "vB");

        printf("\emplace_back(20)\n");
        vB.emplace_back(20);
        Print(vB, "vB");

        printf("\emplace_back(30)\n");
        vB.emplace_back(30);
        Print(vB, "vB");

        printf("\nvB/emplace_back end\n");
    }
    printf("new int is called %d times.\n", B::newCounter);

    return 0;
}





 

Program Output

vA/push_back Begin
push_back(10)
Ctor(int) this=408, p=400, *p=10
Copy ctor this=424, p=416, *p=10
Dtor  del this=408, p=400, *p=10
 &(vA[0])=424, p=416, *p=10

push_back(20)
Ctor(int) this=440, p=432, *p=20
Copy ctor this=456, p=448, *p=20
Copy ctor this=472, p=464, *p=10
Dtor  del this=424, p=416, *p=10
Dtor  del this=440, p=432, *p=20
 &(vA[0])=472, p=464, *p=10
 &(vA[1])=456, p=448, *p=20

push_back(30)
Ctor(int) this=488, p=480, *p=30
Copy ctor this=496, p=416, *p=30
Copy ctor this=512, p=504, *p=10
Copy ctor this=528, p=520, *p=20
Dtor  del this=472, p=464, *p=10
Dtor  del this=456, p=448, *p=20
Dtor  del this=488, p=480, *p=30
 &(vA[0])=512, p=504, *p=10
 &(vA[1])=528, p=520, *p=20
 &(vA[2])=496, p=416, *p=30

vA/push_back end
Dtor  del this=512, p=504, *p=10
Dtor  del this=528, p=520, *p=20
Dtor  del this=496, p=416, *p=30
new int is called 9 times.

vA/emplace_back Begin
emplace_back(10)
Ctor(int) this=472, p=480, *p=10
 &(vA[0])=472, p=480, *p=10

emplace_back(20)
Ctor(int) this=544, p=536, *p=20
Copy ctor this=560, p=552, *p=10
Dtor  del this=472, p=480, *p=10
 &(vA[0])=560, p=552, *p=10
 &(vA[1])=544, p=536, *p=20

emplace_back(30)
Ctor(int) this=576, p=568, *p=30
Copy ctor this=592, p=584, *p=10
Copy ctor this=608, p=600, *p=20
Dtor  del this=560, p=552, *p=10
Dtor  del this=544, p=536, *p=20
 &(vA[0])=592, p=584, *p=10
 &(vA[1])=608, p=600, *p=20
 &(vA[2])=576, p=568, *p=30

vA/emplace_back end
Dtor  del this=592, p=584, *p=10
Dtor  del this=608, p=600, *p=20
Dtor  del this=576, p=568, *p=30
new int is called 6 times.

vB/push_back begin
push_back(10)
Ctor(int) this=624, p=616, *p=10
Move ctor this=632, p=616, *p=10, &rhs=624
Dtor      this=624, p=nullptr
 &(vB[0])=632, p=616, *p=10

push_back(20)
Ctor(int) this=648, p=640, *p=20
Move ctor this=656, p=640, *p=20, &rhs=648
Move ctor this=664, p=616, *p=10, &rhs=632
Dtor      this=632, p=nullptr
Dtor      this=648, p=nullptr
 &(vB[0])=664, p=616, *p=10
 &(vB[1])=656, p=640, *p=20

push_back(30)
Ctor(int) this=680, p=672, *p=30
Move ctor this=688, p=672, *p=30, &rhs=680
Move ctor this=696, p=616, *p=10, &rhs=664
Move ctor this=704, p=640, *p=20, &rhs=656
Dtor      this=664, p=nullptr
Dtor      this=656, p=nullptr
Dtor      this=680, p=nullptr
 &(vB[0])=696, p=616, *p=10
 &(vB[1])=704, p=640, *p=20
 &(vB[2])=688, p=672, *p=30

vB/push_back end
Dtor  del this=696, p=616, *p=10
Dtor  del this=704, p=640, *p=20
Dtor  del this=688, p=672, *p=30
new int is called 3 times.

vB/emplace_back begin
emplace_back(10)
Ctor(int) this=712, p=552, *p=10
 &(vB[0])=712, p=552, *p=10
emplace_back(20)
Ctor(int) this=728, p=720, *p=20
Move ctor this=632, p=552, *p=10, &rhs=712
Dtor      this=712, p=nullptr
 &(vB[0])=632, p=552, *p=10
 &(vB[1])=728, p=720, *p=20
emplace_back(30)
Ctor(int) this=576, p=448, *p=30
Move ctor this=592, p=552, *p=10, &rhs=632
Move ctor this=608, p=720, *p=20, &rhs=728
Dtor      this=632, p=nullptr
Dtor      this=728, p=nullptr
 &(vB[0])=592, p=552, *p=10
 &(vB[1])=608, p=720, *p=20
 &(vB[2])=576, p=448, *p=30

vB/emplace_back end
Dtor  del this=592, p=552, *p=10
Dtor  del this=608, p=720, *p=20
Dtor  del this=576, p=448, *p=30
new int is called 3 times.

Friday, August 11, 2023

How to Show Remote Ubuntu Desktop screen from Windows computer

Terminology

  • X server: it runs on Windows, wait connection from Ubuntu and provides display, mouse, keyboard to X client that connected onto windows computer. Cygwin/X is used.
  • X client: it runs on Ubuntu and connect to Windows and show GUI onto X Server on Windows. gnome-session, gnome-terminal,  firefox, xclock, xeyes, ...
  • SSH server: it runs on Ubuntu and wait connection from Windows computer. openssh-server is used.
  • SSH client: it runs on Windows and connect to SSH server. Teraterm is used.

There are two physical computers, Windows computer and Ubuntu computer. I'm going to do the following things: On Windows, start Cygwin/X to wait to accept remote X client connection, then run Teraterm  to connect Ubuntu and run some X client on Ubuntu to connect to Cygwin/X of Windows to show Ubuntu GUI on Windows computer screen.

Setup ssh on Ubuntu computer

On Ubuntu computer, apt install ssh to install/enable sshd. 

sudo apt install openssh-server

 

And allow ssh connection to firewall by

sudo ufw allow ssh
 

Determine your Ubuntu computer IP address

 

Check ip address of your Ubuntu computer. On Ubuntu computer, open Terminal and type

ifconfig

 

In my case, it is 192.168.11.103


Connect Ubuntu from Windows computer using Tera term via SSH

 

On Windows computer, visit 

    https://teratermproject.github.io/index-en.html

 and download Teraterm installer.


On installation, make sure to choose to install "Teraeterm Menu" feature and set it runs on Windows startup. 

 

After install, right click Teraterm Menu icon on system tray and add your Ubuntu computer IP address, username, password and enable ssh. 

 

Left click Teraterm menu icon on the system tray, choose your Ubuntu connection profile to connect to Ubuntu.


Determine your Windows computer IP address

 

On Windows, run cmd and type 

ipconfig

 

It shows IP address of your computer. My Windows computer IP is 192.168.11.199


Install Cygwin/X on Windows

 

Install Cygwin/X onto Windows computer https://x.cygwin.com/

 

My Cygwin installation directory is C:\cygwin64

On Cygwin installation, check xterm and xhost from package selection


Open C:\cygwin64\bin\startxwin with your text editor (I use Sakura editor) and modify

serverargs="" with

serverargs="+iglx -wgl -listen tcp"


On windows start menu, choose Cygwin-X → Xwin server to run Cygwin X server.


Disable X server authentication of Windows Cygwin/X server to allow connection from Ubuntu



On Windows, left click Cygwin/X icon on system tray, choose System tools → XTerm to run xterm
On XTerm window, type
 
xhost +


Connect Ubuntu from Windows computer using Teraterm via SSH

On Windows, left click Teraterm menu and connect to Ubuntu computer.

Type the following commands on Teraterm command prompt to run gnome desktop session onto your Cygwin/X X server.

export DISPLAY="192.168.11.199:0"

export WAYLAND_DISPLAY="192.168.11.199:0"

export XDG_SESSION_TYPE=x11

gnome-session


Where 192.168.11.199 is IP address of my Windows, that is determined by ipconfig on the earlier step. 

 Ubuntu desktop is shown on your Windows computer. Remote Ubuntu computer can be used as a local native Ubuntu computer from Windows


If it is not necessary to run whole Ubuntu desktop on your Windows desktop, just run gnome-terminal or xterm instead of gnome-session


MobaXterm


There is relatively new X server program called MobaXterm. I don't tested it but maybe it is easier to use



Wednesday, August 2, 2023

How to add language input method to offline Windows 11 22H2 computer

For this topic, Internet information seems a bit unreliable because language feature installation process is completely changed on Windows 11. 

Follow these steps.


Step 1

Download Windows 11 Languages and Optional Features, version 22H2 iso file from your Visual Studio Subscription page.

 

 

Step 2

Mount downloaded iso using Windows Explorer, double-click download iso to mount it.

In my case, iso image is mounted as H:\

 

Step 3

Run cmd as administrator  and type those commands to install language packs. "ja-JP" means Japanese. Change it to your language code. H:\ should be replaced your mounted iso image drive letter.

dism /online /add-capability /capabilityname:Language.Basic~~~ja-JP~0.0.1.0 /source:H:\LanguagesAndOptionalFeatures /LimitAccess
dism /online /add-capability /capabilityname:Language.Handwriting~~~ja-JP~0.0.1.0 /source:H:\LanguagesAndOptionalFeatures /LimitAccess
dism /online /add-capability /capabilityname:Language.OCR~~~ja-JP~0.0.1.0 /source:H:\LanguagesAndOptionalFeatures /LimitAccess
dism /online /add-capability /capabilityname:Language.Speech~~~ja-JP~0.0.1.0 /source:H:\LanguagesAndOptionalFeatures /LimitAccess
dism /online /add-capability /capabilityname:Language.TextToSpeech~~~ja-JP~0.0.1.0 /source:H:\LanguagesAndOptionalFeatures /LimitAccess
dism /online /add-capability /capabilityname:Language.Fonts.Jpan~~~und-JPAN~0.0.1.0 /source:H:\LanguagesAndOptionalFeatures /LimitAccess

 

Step 4

 
Open settings (right click start icon and choose Settings) → Time & Language → Lauguage & region, push "Add a language" button to add language. Some caution message such as your computer is offline may be shown but adding language should work.

Some thoughts

The dism command argument /online does not mean internet connection, it means language pack will be installed onto currently running OS.

Without /LimitAccess option, dism try to connect internet.

It seems /add-package option is deprecated and replaced to /add-capability


 



Saturday, August 6, 2022

AVX512 vbroadcast instructions

It is possible to broadcast 8bit, 16bit, 32bit, 64bit, 128bit and 256bit data onto 512bit register using AVX512 vpbroadcast/vbroadcast instructions.

  • vpbroadcastb zmm1, xmm2/m8 is AVX512BW.
  • vpbroadcastw zmm1, xmm2/m16 is AVX512BW.
  • vpbroadcastd zmm1, xmm2/m32 is AVX512F.
  • vpbroadcastq zmm1, xmm2/m64 is AVX512F.
  • vbroadcasti32x2 zmm1, xmm2/m64 is AVX512DQ.
  • vbroadcasti32x4 zmm1, m128 is AVX512F.
  • vbroadcasti64x2 zmm1, m128 is AVX512DQ.
  • vbroadcasti32x8 zmm1, m256 is AVX512DQ.
  • vbroadcasti64x4 zmm1, m256 is AVX512F.

On large data broadcasts, there is a choice to broadcast data with the same pattern, if it is to simply broadcast data,

  • vpbroadcastq is preferable than vbroadcasti32x2
  • vbroadcasti32x4 is preferable than vbroadcasti64x2
  • vbroadcast64x4 is preferable than vbroadcasti32x8

because the former is more standard AVX512F instruction.

 

References

  • https://www.officedaytime.com/simd512e/simdimg/si.php?f=vbroadcastf128
  • Intel® 64 and IA-32 Architectures Software Developer’s Manual

 




Saturday, April 16, 2022

How to install Windows 11 Pro on Surface 8 Pro without Microsoft account

 Prerequisites

  • Fresh Surface 8 Pro computer
  • Valid MSDN subscriber account
  • Windows 11 Pro retail license and its USB installer thumbdrive attached
  • Another blank USB thumbdrive

Setup procedure

On Surface8, press Volume+ button on the left and press power button to boot UEFI bios. On security menu, enable secure boot from  "Microsoft and 3rd party". On boot menu, delete existing Microsoft boot loader and enable USB boot with top priority.

On another Windows computer, download Ubuntu 20.04 Desktop x64 iso and create bootable USB using Rufus. Connect it to Surface and boot, Choose try Ubuntu (instead of Install Ubuntu), on Ubuntu start menu, run Terminal. On Terminal, sudo and fdisk /dev/nvme0n1 and delete all 4 partitions with d and write partition table with wq and shutdown the computer.

On another Windows computer, download Windows 10 2004 x64 iso image from MSDN subscriber downloads and create bootable USB using Rufus. Insert it and boot Surface, on network connection selection menu, press "I don't have network connection" on the left bottom of the screen. Installation finishes without entering any product keys, and Windows 10 home is installed.

Boot windows 10, disable all network connections on device manager. Insert Windows 11 pro USB thumbdrive and run setup.exe. Windows 11 Pro is installed without network connection, without Microsoft account.

Boot Windows 11, Enable the network connection on device manager. On Settings menu →System→Activation, press Change product key and enter your Windows 11 Pro retail license product key. Activation succeeded.


 

 

Monday, March 15, 2021

How to Unleash CUDA performance of Titan V on Windows 10

Titan V GPU clock is capped at 1335MHz when it is used as CUDA compute device.

 Fig.1 GPU Clock is capped at 1335MHz

 

In order to lift this performance cap and draw full CUDA performance from Titan V, it is necessary to run the following nvidia-smi command with administrators privilege:

"C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe" --cuda-clocks=OVERRIDE


Fig.2 GPU Clock is increased to 1575MHz



Thursday, November 19, 2020

Creating Pre-emphasis Audio CD (CD-R, technically)

Creating FIR filter coefficients of pre-emphasis

Pre-emphasis frequency  response PdB(f) = - TdB(f) for all frequencies f.
-log10x=log10 ( 1x) therefore

De-emphasis TdB(f) =10log10( 1+ 1 (0.000015·2πf)2 1+ 1 (0.00005·2πf)2 )-10.4576……(1)
f : frequency (Hz)
TdB(f) : De-emphasis filter gain (dB)

Pre-emphasis PdB(f) =10log10( 1+ 1 (0.00005·2πf)2 1+ 1 (0.000015·2πf)2 )+10.4576……(2)
f : frequency (Hz)
PdB(f) : Pre-emphasis filter gain (dB)

Note: Math equations of this article uses MathML and it seems it is displayed correctly only on Firefox (as of November 2020).

Now we have frequency response equation of pre-emphasis (2) and FIR filter coefficients can be calculated from  (2) using frequency sampling method, which is explained on the previous article.

Burning Audio CD-R with pre-emphasis

I used Windows PC for the following tasks.

 

Prepare Audio tracks with pre-emphasised

Prepare sound tracks of our Audio CD. 

PCM should be pre-emphasis filtered 44.1kHz 16bit WAV.

 I prepared the CD track WAV files Track01.wav and Track02.wav on C:\audio folder.

 

Install Cygwin and cdrecord

Download and run Cygwin setup-x86_64.exe https://www.cygwin.com/ 

Install cdrecord package: On the Select Packages menu on the Cygwin installer, Set View to "Full" and input "cdr" to Search. cdrecord package will be shown. On the pulldown list of the New column, select cdrecord version number to install.


Burn Pre-emphasis Audio data to CD-R 

Connect CD-R, DVD-R or BD-RW drive to the computer and insert CD-R.

Start → Cygwin → Cygwin64 Terminal.

Change current directory to C:\audio . Type the following text on the Cygwin64 Terminal :

$ cd /cygdrive/c/audio

Then type ls to show the file list of C:\audio folder. Make sure your wav files are there.

Create Audio CD with pre-emphasis:

$ cdrecord -audio -preemp Track01.wav Track02.wav


View Burned Audio CD-R track info using Exact Audio Copy


It seems Pre-emp is "Yes" 😄

Reading Channel status bit of S/PDIF signal from CD player

Inserted created pre-emphasis CD-R to a CD transport Marantz SA-15S1 and played. And watched its S/PDIF signal using RME Fireface UC and found emphasis flag of channel status is "None". This means the CD transport de-emphasised PCM signal in digital domain and no further de-emphasis is necessary on receiver/DAC. 

It is possible to de-emphasis pre-emphasised PCM signal by playing it on the CD transport and recording S/PDIF signal using PCM recorder.

Pre-emphasis FIR Filter coefficients of 27 taps

This FIR filter is for 44.1kHz PCM.

-0.0001031041010544631,
3.9223988214258376E-05,
-0.00035340551190767011,
8.1196136261327267E-05,
-0.00091024157376404236,
-0.00022270417890876693,
-0.0025945766943699933,
-0.0022553226067039134,
-0.009562843431584811,
-0.015097813965845558,
-0.051492871033445048,
-0.11992388565207374,
-0.44071105358364959,
2.2862148044176558,
-0.44071105358364959,
-0.11992388565207374,
-0.051492871033445048,
-0.015097813965845558,
-0.009562843431584811,
-0.0022553226067039134,
-0.0025945766943699933,
-0.00022270417890876693,
-0.00091024157376404236,
8.1196136261327267E-05,
-0.00035340551190767011,
3.9223988214258376E-05,
-0.0001031041010544631,

Filtering sound files using sox

The following examples inputs 44.1kHz PCM file inFile.flac and apply 27taps Pre-emphasis FIR filter and output it as outFile.flac (this filter increases gain so sample value overflow may occur):

sox inFile.flac outFile.flac fir -0.0001031041010544631 3.9223988214258376E-05 -0.00035340551190767011 8.1196136261327267E-05 -0.00091024157376404236 -0.00022270417890876693 -0.0025945766943699933 -0.0022553226067039134 -0.009562843431584811 -0.015097813965845558 -0.051492871033445048 -0.11992388565207374 -0.44071105358364959 2.2862148044176558 -0.44071105358364959 -0.11992388565207374 -0.051492871033445048 -0.015097813965845558 -0.009562843431584811 -0.0022553226067039134 -0.0025945766943699933 -0.00022270417890876693 -0.00091024157376404236 8.1196136261327267E-05 -0.00035340551190767011 3.9223988214258376E-05 -0.0001031041010544631

Wednesday, November 11, 2020

Designing De-emphasis Digital Filter for old CDs Part 3: Using Reference Equation

 There is a reference de-emphasis equation on this page (Thanks miguelito-san) : https://forums.stevehoffman.tv/threads/cd-dat-with-pre-emphasis-how-to-de-emphasize-correctly.88541/

TdB(f) =10log10( 1+ 1 (0.000015·2πf)2 1+ 1 (0.00005·2πf)2 )-10.4576……(1)
f : frequency (Hz)
TdB(f) : De-emphasis filter gain (dB)

This decibel is root power quantity therefore actual gain magnitude value T(f) is:

T(f) = 10TdB(f)/20……(2)
f : frequency (Hz)
T(f) : De-emphasis filter gain magnitude value at frequency f

Note 1: Math equations of this article uses MathML and it seems it is displayed correctly only on Firefox (as of November 2020).

Note 2: It seems 0.00005 and 0.000015 of equation 1 means 50 microseconds and 15 microseconds respectively and it is called 50/15 microsec emphasis.

On this article, equation (2) is used to create frequency sampling FIR digital filter.

Calculation steps are very similar to Part 2.

Example : Calculation of M=9 taps FIR filter coeffs using equation T(f)

Following is the procedure to design a linear-phase FIR filter using frequency sampling method. All the following calculation can be performed using  Excel spreadsheet.

When sampling frequency==44100 Hz and Desired FIR filter taps M==9,

Frequency sampling index k=0,1,2, ... , M-12 = 4, i.e.

k = 0, 1, 2, 3 and 4

We design de-emphasis filter for CD, therefore PCM sampling frequency = 44100Hz.

Frequency sampling angle frequency ωk=2πkM and its respective frequency is:

  • k = 0 :   ω0 = 0, freq0 = 0 Hz
  • k = 1 :   ω1 = 2π/9, freq1 = (44100/2π)(2π/9) = 44100 / 9 Hz = 4900 Hz
  • k = 2 :   ω2 = 4π/9, freq2 = (44100/2π)(4π/9) = 44100 * 2 / 9 Hz = 9800 Hz
  • k = 3 :   ω3 = 6π/9, freq3 = (44100/2π)(6π/9) = 44100 * 3 / 9 Hz = 14700 Hz
  • k = 4 :   ω4 = 8π/9, freq4 = (44100/2π)(8π/9) = 44100 * 4 / 9 Hz = 19600 Hz

Get filter gain on those frequencies Hr(ωk) using Equation (2):

  • Hr(ω0) = T(0) = 1
  • Hr(ω1) = T(4900) = 0.60004356
  • Hr(ω2) = T(9800) = 0.420524967
  • Hr(ω3) = T(14700) = 0.361602897
  • Hr(ω4) = T(19600) = 0.336724814

Then G(k) is calculated from Hr(ωk) by G(k) = (-1)k Hr(ωk) ……(3) :

  • G(0) = (-1)0 Hr(ω0) = 1
  • G(1) = (-1)1 Hr(ω1) = -0.60004356
  • G(2) = (-1)2 Hr(ω2) = 0.420524967
  • G(3) = (-1)3 Hr(ω3) = -0.361602897
  • G(4) = (-1)4 Hr(ω4) = 0.336724814

FIR filter coefficients h(k) can be calculated by h(k) = 1M{G(0)+2 n=1 (M-1)/2 G(n)cos2πn(k+1/2)M} …(4)

  • h(0) = 0.030212113446082472
  • h(1) = 0.040656939222222181
  • h(2) = 0.063594885887469199
  • h(3) = 0.11899203499978166
  • h(4) = 0.49308805288888891

Finally, this FIR filter is symmetry (linear phase), therefore h(8) = h(0), h(7) = h(1), h(6) = h(2), h(5) = h(3).

  • h(0) = 0.030212113446082472
  • h(1) = 0.040656939222222181
  • h(2) = 0.063594885887469199
  • h(3) = 0.11899203499978166
  • h(4) = 0.49308805288888891
  • h(5) = 0.11899203499978166
  • h(6) = 0.063594885887469199
  • h(7) = 0.040656939222222181
  • h(8) = 0.030212113446082472

We've got all the 9 FIR filter coefficients h(n) where n=0, 1, 2, ..., 8

Evaluating Frequency Response of the FIR filter obtained

Now one FIR filter is available for testing. FIR filter gain of arbitrary angular frequency ω can be calculated using the following equation:

Gain(ω) = k=0 M-1 h(k)e-jkω ……(5)

Equation (5) is complex number, which provides more info than we'd like to have (we need only frequency-gain response of the filter: the frequency-phase response is known to be linear with 4 samples of delay, this means frequency-phase error is zero for all frequencies when output signal is shifted by 4 samples to align to input signal). Real part and imaginary part of (5) can be calculated separately:

Gainreal(ω) = k=0 M-1 h(k)cos(-kω) ……(5r)
Gainimaginary(ω) = k=0 M-1 h(k)sin(-kω) ……(5i)

And the FIR filter Gain magnitude is calculated as follows: Gainmagnitude(ω) = Gainreal(ω)2 + Gainimaginary(ω)2 ……(6)

Finally Gain in decibel is: GaindB(ω) = 20log10{Gainmagnitude(ω)} ……(7)

For our M=9 FIR filter, frequency response can be calculated using equation (7). Using the reference equation (1), desirable gain of any frequency can be calculated, it is possible to compare gain values at as many frequency points as you wish. I compared 10Hz to 22040Hz semitone step frequency points and created Fig.1.


Fig.1. 9 taps FIR de-emphasis filter frequency response.

Comparing to the original de-emphasis table, max error of this FIR filter is 0.878 dB on 7360Hz, It is poor. The filtering quality can be improved by increasing M.

Searching the optimal FIR filter tap number M

FIR Filter Taps M Max Error (dB)
9 0.878
15 0.1704
17 0.115
19 0.0631
21 0.0522
23 0.0231
25 0.0272
27 0.00882

Table 1: FIR Filter taps and max error 



Fig.2 : Frequency Response of FIR Filter, taps=19  note: frequency axis is logarithmic.


Fig.3 : Frequency Response of FIR Filter, taps=27  note: frequency axis is logarithmic.


Fig.4 : Gain Error of FIR Filter, taps=27

 

From the Table 1, 

  • If the max error should be below 0.1 dB, use 19-tap FIR filter.
  • If the max error should be below 0.01 dB, use 27-tap FIR filter.

De-emphasis FIR Filter Coefficients for 44.1kHz PCM data

19-tap linear-phase FIR filter coefficients h(k) of max error < 0.1 dB is as follows:

0.0022333652179533105,
0.0027676001211334594,
0.0042218013139663415,
0.0065438712761329912,
0.011312237381544295,
0.01877355043394098,
0.03398288954901494,
0.059120380386441337,
0.11593361915957012,
0.49022137032060437,
0.11593361915957012,
0.059120380386441337,
0.03398288954901494,
0.01877355043394098,
0.011312237381544295,
0.0065438712761329912,
0.0042218013139663415,
0.0027676001211334594,
0.0022333652179533105,

27-tap linear-phase FIR filter coefficients h(k) of max error < 0.01 dB is as follows:

0.00031102739649091732,
0.00036885685453166665,
0.00057659816229764602,
0.00082952248115418167,
0.001449970925925961,
0.0022387507393955598,
0.0039420948394406248,
0.0063363475292175873,
0.011215231698621361,
0.018685854350970088,
0.033951734838472802,
0.059076192885731141,
0.11592376177923121,
0.49018811103703697,
0.11592376177923121,
0.059076192885731141,
0.033951734838472802,
0.018685854350970088,
0.011215231698621361,
0.0063363475292175873,
0.0039420948394406248,
0.0022387507393955598,
0.001449970925925961,
0.00082952248115418167,
0.00057659816229764602,
0.00036885685453166665,
0.00031102739649091732,

If you'd like to listen to poorly designed de-emphasis filter sound to compare to better one, use 9-tap filter coefficients.😀
 

Performing de-emphasis filtering to the pre-emphasised sound file using sox

With sox, it is possible to use those FIR filter coefficients rather direct fashion to filter the 44.1kHz PCM sound files. The following examples inputs inFile.flac and apply 27-tap de-emphasis FIR filter and output it as outFile.flac:

sox inFile.flac outFile.flac fir 0.00031102739649091732 0.00036885685453166665 0.00057659816229764602 0.00082952248115418167 0.001449970925925961 0.0022387507393955598 0.0039420948394406248 0.0063363475292175873 0.011215231698621361 0.018685854350970088 0.033951734838472802 0.059076192885731141 0.11592376177923121 0.49018811103703697 0.11592376177923121 0.059076192885731141 0.033951734838472802 0.018685854350970088 0.011215231698621361 0.0063363475292175873 0.0039420948394406248 0.0022387507393955598 0.001449970925925961 0.00082952248115418167 0.00057659816229764602 0.00036885685453166665 0.00031102739649091732

Search internet for "sox sound exchange" to get your sox copy. It is free of charge.

 

Next article: Creating Pre-emphasis Audio CD