0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

dxgkrnlを有効にしてkernelビルド(5.4.y)

Last updated at Posted at 2021-03-08

カーネルビルド

WSL2上で新しめのカーネルにてdxgkrnlを使う方法
なお、Windowsのバージョンが下記のため、動作確認が取れていない
Microsoft Windows [Version 10.0.21327.1000]

Microsoft Windows [Version 10.0.21332.1000]で動作を確認
linux-msft-wsl-5.10.yのdxgkrnlを使う方法はここ

stableカーネルリポジトリをcloneする

$ git clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
$ cd linux
$ git checkout origin/linux-5.11.y

WSL2のカーネルリポジトリをリモートに追加し、fetchする

$ git remote add wsl-origin https://github.com/microsoft/WSL2-Linux-Kernel.git
$ git fetch wsl-origin linux-msft-wsl-5.4.y

dxgkrnドライバの変更点をcherry-pick

$ git log wsl-origin/linux-msft-wsl-5.4.y --oneline -- drivers/hyperv/dxgkrnl/ | awk '{print $1}' | tac > dxgkrnl_id
$ git cherry-pick `cat dxgkrnl_id`

コンパイルが通るようにソースコードを修正

他にも修正する必要があるかもしれない

$ vi drivers/hyperv/dxgkrnl/dxgvmbus.c
$ git add drivers/hyperv/dxgkrnl/dxgvmbus.c
$ git commit -m "change name from mmap_sem to mmap_lock"

ソースコード修正点

$ git diff HEAD~
diff --git a/drivers/hyperv/dxgkrnl/dxgvmbus.c b/drivers/hyperv/dxgkrnl/dxgvmbus.c
index 0a22d0315d56..76ec1e6bedfb 100644
--- a/drivers/hyperv/dxgkrnl/dxgvmbus.c
+++ b/drivers/hyperv/dxgkrnl/dxgvmbus.c
@@ -550,7 +550,7 @@ static u8 *dxg_map_iospace(u64 iospace_address, u32 size,
                return NULL;
        }

-       down_read(&current->mm->mmap_sem);
+       down_read(&current->mm->mmap_lock);
        vma = find_vma(current->mm, (unsigned long)va);
        if (vma) {
                pgprot_t prot = vma->vm_page_prot;
@@ -568,7 +568,7 @@ static u8 *dxg_map_iospace(u64 iospace_address, u32 size,
                pr_err("failed to find vma: %p %lx", vma, va);
                ret = -ENOMEM;
        }
-       up_read(&current->mm->mmap_sem);
+       up_read(&current->mm->mmap_lock);

        if (ret) {
                dxg_unmap_iospace((void *)va, size);

カーネルビルド&インストール

make oldconfigの設定は適宜行う。

$ make mrproper
$ git show wsl-origin/linux-msft-wsl-5.4.y:Microsoft/config-wsl > .config
$ make oldconfig
$ make
$ cp arch/x86/boot/bzImage /mnt/d/kernel-5.11.4-microsoft-standard-WSL2+

.wslconfigの設定

$ vi /mnt/c/Users/[USERNAME]/.wslconfig
$ cat /mnt/c/Users/[USERNAME]/.wslconfig
[wsl2]
kernel=d:\\kernel-5.11.4-microsoft-standard-WSL2+

動作確認

$ ls /dev/dxg
/dev/dxg
$ /usr/local/cuda-11.2/samples/bin/x86_64/linux/release/deviceQuery
/usr/local/cuda-11.2/samples/bin/x86_64/linux/release/deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GTX 1070"
  CUDA Driver Version / Runtime Version          11.3 / 11.2
  CUDA Capability Major/Minor version number:    6.1
  Total amount of global memory:                 8192 MBytes (8589934592 bytes)
  (15) Multiprocessors, (128) CUDA Cores/MP:     1920 CUDA Cores
  GPU Max Clock rate:                            1709 MHz (1.71 GHz)
  Memory Clock rate:                             4004 Mhz
  Memory Bus Width:                              256-bit
  L2 Cache Size:                                 2097152 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
  Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total shared memory per multiprocessor:        98304 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 1 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device supports Managed Memory:                Yes
  Device supports Compute Preemption:            Yes
  Supports Cooperative Kernel Launch:            Yes
  Supports MultiDevice Co-op Kernel Launch:      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.3, CUDA Runtime Version = 11.2, NumDevs = 1
Result = PASS
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?