AI

NVIDIA GeForce RTX 4060 Laptop GPU CUDA Conda Windows 가상환경 설치

hwpform 2024. 5. 15. 11:20
728x90
반응형
  • PC환경 정보
o  Windows 11에서 conda 가상환경에서 GPU 인식하기 

o  Windows 환경정보 ( DXDIAG 명령어로 확인)
-Windows 11 Pro 64-bit (10.0, Build 22631) (22621.ni_release.220506-1250) 
                                       13th Gen Intel(R) Core(TM) i7-13620H (16 CPUs), ~2.4GHz
- NVIDIA GeForce RTX 4060 Laptop GPU\

o Windows 에 NVIDIA 설치 정보
 - NVIDIA CUDA Version : 12.4
 - NVIDIA Cunna Version : 8.9 

 

  • Windows Conda 가상환경에서 GPU를 사용하려면 다음과 같은 제약조건이 인터넷 검색결과로 나옴
o NVIDIA CUDA Version : 11.x 이하일것 
o NVIDIA Cunna Version : 8.x 이하일것
o Python : 3.10.x 이하일것
o Tensorflow 2.10.x 이하일것

위의 제약조건에 맞게 Conda 가상환경을 만들어 보고 가상환경에서 GPU가 인식되는지 테스트 해봄
 

CUDA Toolkit Archive

Previous releases of the CUDA Toolkit, GPU Computing SDK, documentation and developer drivers can be found using the links below. Please select the release you want from the list below, and be sure to check www.nvidia.com/drivers for more recent production

developer.nvidia.com

 

cuDNN Archive

Download releases from the GPU-accelerated primitive library for deep neural networks.

developer.nvidia.com

 

CUDA - Wikipedia

From Wikipedia, the free encyclopedia Parallel computing platform and programming model Compute Unified Device Architecture (CUDA) is a proprietary[1] parallel computing platform and application programming interface (API) that allows software to use certa

en.wikipedia.org

 

  • NVIDIA Drive 확인 Nvidia-smi 
# C:\Users\shim>nvidia-smi
Wed May 15 12:16:12 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 552.44                 Driver Version: 552.44         CUDA Version: 12.4     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                     TCC/WDDM  | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 4060 ...  WDDM  |   00000000:01:00.0 Off |                  N/A |
| N/A   44C    P8              1W /   80W |       0MiB /   8188MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+

 

  • NVIDIA Cuda 확인 nvcc -V
# C:\Users\shim>nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Mar_28_02:30:10_Pacific_Daylight_Time_2024
Cuda compilation tools, release 12.4, V12.4.131
Build cuda_12.4.r12.4/compiler.34097967_0

 

conda를 통한 가상환경 생성 및 GPU 확인

 

  • conda에서 가상환경 설치하기
# 설치요약

1. 가상환경 디렉토리를 cuda 로 설정
2. python 3.10 설치
3. cudatoolkit 11.2 설치
4. cudnn=8.1.0 설치
5. Tensorflow 2.10 설치
# (base) C:\Users\shim>conda create -n cuda python=3.10
Channels:
 - defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done
<< Package Plan >>
  environment location: C:\Users\shim\anaconda3\envs\cuda
  added / updated specs:
    - python=3.10
The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    pip-24.0                   |  py310haa95532_0         2.9 MB
    python-3.10.14             |       he1021f5_1        15.9 MB
    setuptools-69.5.1          |  py310haa95532_0        1013 KB
    wheel-0.43.0               |  py310haa95532_0         136 KB
    ------------------------------------------------------------
                                           Total:        20.0 MB
The following NEW packages will be INSTALLED:
  bzip2              pkgs/main/win-64::bzip2-1.0.8-h2bbff1b_6
  ca-certificates    pkgs/main/win-64::ca-certificates-2024.3.11-haa95532_0
  libffi             pkgs/main/win-64::libffi-3.4.4-hd77b12b_1
  openssl            pkgs/main/win-64::openssl-3.0.13-h2bbff1b_1
  pip                pkgs/main/win-64::pip-24.0-py310haa95532_0
  python             pkgs/main/win-64::python-3.10.14-he1021f5_1
  setuptools         pkgs/main/win-64::setuptools-69.5.1-py310haa95532_0
  sqlite             pkgs/main/win-64::sqlite-3.45.3-h2bbff1b_0
  tk                 pkgs/main/win-64::tk-8.6.14-h0416ee5_0
  tzdata             pkgs/main/noarch::tzdata-2024a-h04d1e81_0
  vc                 pkgs/main/win-64::vc-14.2-h21ff451_1
  vs2015_runtime     pkgs/main/win-64::vs2015_runtime-14.27.29016-h5e58377_2
  wheel              pkgs/main/win-64::wheel-0.43.0-py310haa95532_0
  xz                 pkgs/main/win-64::xz-5.4.6-h8cc25b3_1
  zlib               pkgs/main/win-64::zlib-1.2.13-h8cc25b3_1

Proceed ([y]/n)? y
Downloading and Extracting Packages:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
 To activate this environment, use
     $ conda activate cuda
 To deactivate an active environment, use
     $ conda deactivate
     
# (base) C:\Users\shim>conda env list
 conda environments:
base                  *  C:\Users\shim\anaconda3
cuda                     C:\Users\shim\anaconda3\envs\cuda
llm                      C:\Users\shim\anaconda3\envs\llm
textgen2                 C:\Users\shim\anaconda3\envs\textgen2

# (base) C:\Users\shim>conda activate cuda
# (cuda) C:\Users\shim>conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0
Channels:
 - conda-forge
 - defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done
<< Package Plan >>
  environment location: C:\Users\shim\anaconda3\envs\cuda
  added / updated specs:
    - cudatoolkit=11.2
    - cudnn=8.1.0
The following packages will be downloaded:
    package                    |            build
    ---------------------------|-----------------
    cudatoolkit-11.2.2         |      h7d7167e_13       634.5 MB  conda-forge
    cudnn-8.1.0.77             |       h3e0f4f4_0       610.8 MB  conda-forge
"By downloading and using the cuDNN conda packages, you accept the terms and conditions of the NVID
done

# (cuda) C:\Users\shim>python -m pip install "tensorflow<2.11"
Collecting tensorflow<2.11
  Downloading tensorflow-2.10.1-cp310-cp310-win_amd64.whl.metadata (3.1 kB)
Collecting absl-py>=1.0.0 (from tensorflow<2.11)
  Using cached absl_py-2.1.0-py3-none-any.whl.metadata (2.3 kB)
  
... 중간 생략
Downloading pyasn1_modules-0.4.0-py3-none-any.whl (181 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 181.2/181.2 kB 5.5 MB/s eta 0:00:00
Using cached urllib3-2.2.1-py3-none-any.whl (121 kB)
Downloading oauthlib-3.2.2-py3-none-any.whl (151 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 151.7/151.7 kB 4.6 MB/s eta 0:00:00
Downloading pyasn1-0.6.0-py2.py3-none-any.whl (85 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 85.3/85.3 kB ? eta 0:00:00
Installing collected packages: tensorboard-plugin-wit, libclang, keras, flatbuffers, wrapt, urllib3, typing-extensions, termcolor, tensorflow-io-gcs-filesystem, tensorflow-estimator, tensorboard-data-server, six, pyasn1, protobuf, packaging, oauthlib, numpy, MarkupSafe, markdown, idna, grpcio, gast, charset-normalizer, certifi, cachetools, absl-py, werkzeug, rsa, requests, pyasn1-modules, opt-einsum, keras-preprocessing, h5py, google-pasta, astunparse, requests-oauthlib, google-auth, google-auth-oauthlib, tensorboard, tensorflow
Successfully installed MarkupSafe-2.1.5 absl-py-2.1.0 astunparse-1.6.3 cachetools-5.3.3 certifi-2024.2.2 charset-normalizer-3.3.2 flatbuffers-24.3.25 gast-0.4.0 google-auth-2.29.0 google-auth-oauthlib-0.4.6 google-pasta-0.2.0 grpcio-1.63.0 h5py-3.11.0 idna-3.7 keras-2.10.0 keras-preprocessing-1.1.2 libclang-18.1.1 markdown-3.6 numpy-1.26.4 oauthlib-3.2.2 opt-einsum-3.3.0 packaging-24.0 protobuf-3.19.6 pyasn1-0.6.0 pyasn1-modules-0.4.0 requests-2.31.0 requests-oauthlib-2.0.0 rsa-4.9 six-1.16.0 tensorboard-2.10.1 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.1 tensorflow-2.10.1 tensorflow-estimator-2.10.0 tensorflow-io-gcs-filesystem-0.31.0 termcolor-2.4.0 typing-extensions-4.11.0 urllib3-2.2.1 werkzeug-3.0.3 wrapt-1.16.0

 

  • conda 가상환경 GPU 확인 실행 테스트 및 결과
# (cuda) C:\Users\shim>python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

# (cuda) C:\Users\shim>python
Python 3.10.14 | packaged by Anaconda, Inc. | (main, May  6 2024, 19:44:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
# >>> from tensorflow.python.client import device_lib
# >>> device_lib.list_local_devices()
2024-05-15 11:54:20.473703: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1616] Created device /device:GPU:0 with 5449 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 4060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.9
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 11119453684472034767
xla_global_id: -1
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 5713690624
locality {
  bus_id: 1
  links {
  }
}
incarnation: 4304763808021192206
physical_device_desc: "device: 0, name: NVIDIA GeForce RTX 4060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.9"
xla_global_id: 416903419
]

# >>> gpus = tf.config.experimental.list_physical_devices('GPU')
# >>> for gpu in gpus:
...     print(gpu)
...
PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')

# >>> import tensorflow as tf
# >>> print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
Num GPUs Available:  1

 

  • Vitual Studio Code 에서 실행결과
# 파이선 코드
import tensorflow as tf
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
print("Num GPUs AVAILABLE: ", len(tf.config.list_physical_devices('GPU')))

# 실행결과

PS C:\Users\shim\anaconda3\envs\cuda> & c:/Users/shim/anaconda3/envs/cuda/python.exe c:/Users/shim/anaconda3/envs/cuda/cuda_gpu_test.py
2024-05-15 12:53:21.191667: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-05-15 12:53:21.806525: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1616] Created device /device:GPU:0 with 5449 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 4060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.9
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 18426872582674291349
xla_global_id: -1
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 5713690624
locality {
  bus_id: 1
  links {
  }
}
incarnation: 3688180905390782346
physical_device_desc: "device: 0, name: NVIDIA GeForce RTX 4060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.9"
xla_global_id: 416903419
]
Num GPUs AVAILABLE:  1

 

  • conda 가상환경 패키지 설치 정보 확인
# conda 환경에 cudatoolkit 11.2.2, cudnn 8.1.0.77, python 3.10.14, tensorflow 2.10.1이
  설치되어 있는것을 확인할수 있다.

#(cuda) C:\Users\shim\anaconda3\envs\cuda>conda list
 packages in environment at C:\Users\shim\anaconda3\envs\cuda:

$ Name                    Version                   Build  Channel
absl-py                   2.1.0                    pypi_0    pypi
astunparse                1.6.3                    pypi_0    pypi
bzip2                     1.0.8                h2bbff1b_6
ca-certificates           2024.3.11            haa95532_0
cachetools                5.3.3                    pypi_0    pypi
certifi                   2024.2.2                 pypi_0    pypi
charset-normalizer        3.3.2                    pypi_0    pypi
cudatoolkit               11.2.2              h7d7167e_13    conda-forge
cudnn                     8.1.0.77             h3e0f4f4_0    conda-forge
flatbuffers               24.3.25                  pypi_0    pypi
gast                      0.4.0                    pypi_0    pypi
google-auth               2.29.0                   pypi_0    pypi
google-auth-oauthlib      0.4.6                    pypi_0    pypi
google-pasta              0.2.0                    pypi_0    pypi
grpcio                    1.63.0                   pypi_0    pypi
h5py                      3.11.0                   pypi_0    pypi
idna                      3.7                      pypi_0    pypi
keras                     2.10.0                   pypi_0    pypi
keras-preprocessing       1.1.2                    pypi_0    pypi
libclang                  18.1.1                   pypi_0    pypi
libffi                    3.4.4                hd77b12b_1
markdown                  3.6                      pypi_0    pypi
markupsafe                2.1.5                    pypi_0    pypi
numpy                     1.26.4                   pypi_0    pypi
oauthlib                  3.2.2                    pypi_0    pypi
openssl                   3.3.0                hcfcfb64_0    conda-forge
opt-einsum                3.3.0                    pypi_0    pypi
packaging                 24.0                     pypi_0    pypi
pip                       24.0            py310haa95532_0
protobuf                  3.19.6                   pypi_0    pypi
pyasn1                    0.6.0                    pypi_0    pypi
pyasn1-modules            0.4.0                    pypi_0    pypi
python                    3.10.14              he1021f5_1
requests                  2.31.0                   pypi_0    pypi
requests-oauthlib         2.0.0                    pypi_0    pypi
rsa                       4.9                      pypi_0    pypi
setuptools                69.5.1          py310haa95532_0
six                       1.16.0                   pypi_0    pypi
sqlite                    3.45.3               h2bbff1b_0
tensorboard               2.10.1                   pypi_0    pypi
tensorboard-data-server   0.6.1                    pypi_0    pypi
tensorboard-plugin-wit    1.8.1                    pypi_0    pypi
tensorflow                2.10.1                   pypi_0    pypi
tensorflow-estimator      2.10.0                   pypi_0    pypi
tensorflow-io-gcs-filesystem 0.31.0                   pypi_0    pypi
termcolor                 2.4.0                    pypi_0    pypi
tk                        8.6.14               h0416ee5_0
typing-extensions         4.11.0                   pypi_0    pypi
tzdata                    2024a                h04d1e81_0
ucrt                      10.0.22621.0         h57928b3_0    conda-forge
urllib3                   2.2.1                    pypi_0    pypi
vc                        14.2                 h21ff451_1
vc14_runtime              14.38.33130         h82b7239_18    conda-forge
vs2015_runtime            14.38.33130         hcb4865c_18    conda-forge
werkzeug                  3.0.3                    pypi_0    pypi
wheel                     0.43.0          py310haa95532_0
wrapt                     1.16.0                   pypi_0    pypi
xz                        5.4.6                h8cc25b3_1
zlib                      1.2.13               h8cc25b3_1

(cuda) C:\Users\shim\anaconda3\envs\cuda>

 

 

728x90
반응형
LIST