From T3_KR_KNU
(→HTCondor 에서 GPU 사용하기) |
(→HTCondor에서 GPU 사용하기) |
||
Line 43: | Line 43: | ||
request_CPUs = 1 | request_CPUs = 1 | ||
queue | queue | ||
+ | |||
+ | === Ex 2) TensorFlow === | ||
+ | |||
+ | tf_ex.py | ||
+ | |||
+ | import tensorflow as tf | ||
+ | |||
+ | mnist = tf.keras.datasets.mnist | ||
+ | |||
+ | (x_train, y_train), (x_test, y_test) = mnist.load_data() | ||
+ | x_train, x_test = x_train / 255.0, x_test / 255.0 | ||
+ | |||
+ | model = tf.keras.models.Sequential([ | ||
+ | tf.keras.layers.Flatten(input_shape=(28, 28)), | ||
+ | tf.keras.layers.Dense(128, activation='relu'), | ||
+ | tf.keras.layers.Dropout(0.2), | ||
+ | tf.keras.layers.Dense(10, activation='softmax') | ||
+ | ]) | ||
+ | |||
+ | model.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy']) | ||
+ | |||
+ | model.fit(x_train, y_train, epochs=5) | ||
+ | model.evaluate(x_test, y_test, verbose=2) | ||
+ | |||
+ | === Ex 3) Singularity & TensorFlow - cvmfs image === | ||
+ | |||
+ | === Ex 4) Singularity & TensorFlow - local image === | ||
+ | |||
+ | === Ex 5) Singularity & TensorFlow - docker image === | ||
+ | |||
+ | === 참고자료 === |
Revision as of 02:07, 12 May 2021
Contents
HTCondor에서 GPU 사용하기
Ex 1) Matrix
matrix.py
import numpy as np from timeit import default_timer as timer from numba import vectorize @vectorize(['float32(float32, float32)'], target='cuda') def pow(a, b): return a ** b vec_size = 100000000 a = b = np.array(np.random.sample(vec_size), dtype=np.float32) c = np.zeros(vec_size, dtype=np.float32) start = timer() c = pow(a,b) duration = timer() - start print(duration)
matrix.sh
#!/bin/bash python3.6 -m virtualenv myvenv source myvenv/bin/activate pip3 install numba python3.6 matrix.py
matrix.sub
executable = matrix.sh arguments = $(ClusterId)$(ProcId) output = matrix.$(ClusterId).$(ProcId).out error = matrix.$(ClusterId).$(ProcId).err log = matrix.$(ClusterId).log should_transfer_files = YES transfer_input_files = matrix.py when_to_transfer_output = ON_EXIT request_GPUs = 1 request_CPUs = 1 queue
Ex 2) TensorFlow
tf_ex.py
import tensorflow as tf mnist = tf.keras.datasets.mnist (x_train, y_train), (x_test, y_test) = mnist.load_data() x_train, x_test = x_train / 255.0, x_test / 255.0 model = tf.keras.models.Sequential([ tf.keras.layers.Flatten(input_shape=(28, 28)), tf.keras.layers.Dense(128, activation='relu'), tf.keras.layers.Dropout(0.2), tf.keras.layers.Dense(10, activation='softmax') ]) model.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy']) model.fit(x_train, y_train, epochs=5) model.evaluate(x_test, y_test, verbose=2)