这是一个相当简单的问题,但谷歌搜索似乎没有答案,所以.
我想知道的是,如果我有两个能够运行cuda的gpu卡(相同),我的内核可以跨越这些卡吗?或者是一张卡还是另一张卡?即,cuda提供了整套可用的gpu核心,或者只是运行在卡上的那些核心.
如果是这样,为了实现它,我需要知道什么特别的事情吗?除了值得了解的cuda sdk之外还有什么例子吗?
目标语言当然是C/C++.
提前致谢.
我使用 Keras API 在 Tensorflow 2.0 中训练了一个包含 RNN 的文本分类模型。我使用tf.distribute.MirroredStrategy()
from here在多个 GPU(2) 上训练了这个模型。我tf.keras.callbacks.ModelCheckpoint('file_name.h5')
在每个纪元之后使用保存了模型的检查点。现在,我想继续训练,从我保存的最后一个检查点开始使用相同数量的 GPU。tf.distribute.MirroredStrategy()
像这样在里面加载检查点后 -
mirrored_strategy = tf.distribute.MirroredStrategy()
with mirrored_strategy.scope():
model =tf.keras.models.load_model('file_name.h5')
Run Code Online (Sandbox Code Playgroud)
,它抛出以下错误。
File "model_with_tfsplit.py", line 94, in <module>
model =tf.keras.models.load_model('TF_model_onfull_2_03.h5') # Loading for retraining
File "/home/rishabh/.local/lib/python2.7/site-packages/tensorflow_core/python/keras/saving/save.py", line 138, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
File "/home/rishabh/.local/lib/python2.7/site-packages/tensorflow_core/python/keras/saving/hdf5_format.py", line 187, in load_model_from_hdf5
model._make_train_function()
File "/home/rishabh/.local/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/training.py", line 2015, in _make_train_function
params=self._collected_trainable_weights, loss=self.total_loss)
File "/home/rishabh/.local/lib/python2.7/site-packages/tensorflow_core/python/keras/optimizer_v2/optimizer_v2.py", line 500, in get_updates
grads = self.get_gradients(loss, params)
File "/home/rishabh/.local/lib/python2.7/site-packages/tensorflow_core/python/keras/optimizer_v2/optimizer_v2.py", line 391, …
Run Code Online (Sandbox Code Playgroud) 我正在使用GPU在多个GPU系统上运行cuda内核功能4
.我预计它们会同时发布,但事实并非如此.我测量每个内核的开始时间,第二个内核在第一个内核完成执行后开始.因此,在4
GPU 上启动内核并不比1
单GPU 快.
如何让它们同时工作?
这是我的代码:
cudaSetDevice(0);
GPU_kernel<<< gridDim, threadsPerBlock >>>(d_result_0, parameterA +(0*rateA), parameterB + (0*rateB));
cudaMemcpyAsync(h_result_0, d_result_0, mem_size_result, cudaMemcpyDeviceToHost);
cudaSetDevice(1);
GPU_kernel<<< gridDim, threadsPerBlock >>>(d_result_1, parameterA +(1*rateA), parameterB + (1*rateB));
cudaMemcpyAsync(h_result_1, d_result_1, mem_size_result, cudaMemcpyDeviceToHost);
cudaSetDevice(2);
GPU_kernel<<< gridDim, threadsPerBlock >>>(d_result_2, parameterA +(2*rateA), parameterB + (2*rateB));
cudaMemcpyAsync(h_result_2, d_result_2, mem_size_result, cudaMemcpyDeviceToHost);
cudaSetDevice(3);
GPU_kernel<<< gridDim, threadsPerBlock >>>(d_result_3, parameterA +(3*rateA), parameterB + (3*rateB));
cudaMemcpyAsync(h_result_3, d_result_3, mem_size_result, cudaMemcpyDeviceToHost);
Run Code Online (Sandbox Code Playgroud) 我正在阅读专业CUDA C编程,并在GPU架构概述部分:
CUDA采用单指令多线程(SIMT)架构来管理和执行32个被称为warp的组中的线程.warp中的所有线程同时执行相同的指令.每个线程都有自己的指令地址计数器和寄存器状态,并对自己的数据执行当前指令.每个SM将分配给它的线程块分区为32线程warp,然后调度它以便在可用的硬件资源上执行.
SIMT架构类似于SIMD(单指令,多数据)架构.SIMD和SIMT都通过向多个执行单元广播相同的指令来实现并行性.一个关键的区别是SIMD要求向量中的所有向量元素在一个统一的同步组中一起执行,而SIMT允许同一warp中的多个线程独立执行.即使warp中的所有线程在同一程序地址处一起启动,单个线程也可能具有不同的行为.SIMT使您能够为独立的标量线程编写线程级并行代码,以及为协调线程编写数据并行代码.SIMT模型包括SIMD不具备的三个关键功能:
➤每个线程都有自己的指令地址计数器.
➤每个线程都有自己的寄存器状态.
➤每个线程都可以有一个独立的执行路径.
第一段提到" All threads in a warp execute the same instruction at the same time.
",而在第二段则提到" Even though all threads in a warp start together at the same program address, it is possible for individual threads to have different behavior.
".这让我感到困惑,上述陈述似乎是矛盾的.任何人都可以解释一下吗?
我有一个看起来像这样的结构
struct LstmLayer {
int deviceId;
thrust::device_vector <real_t> W;
thrust::device_vector <real_t> gradW;
LstmLayer() : deviceId(0) {}
LstmLayer(int __deviceId__) : deviceId(__deviceId__) {}
void setDevice(int __deviceId__) { deviceId = __deviceId__; }
void init(bool initParams) {
W.resize(4*lstmSize * 2*lstmSize);
gradW.resize(4*lstmSize * 2*lstmSize);
if (initParams) GPU_Random_Vector(W);
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想初始化一个数组LstmLayer
,每个元素都在不同的GPU设备上.我这样做如下
struct LstmLayer lstmLayers[MAX_NUM_LSTM_LAYERS];
for (int i = 0; i < numLstmLayers; ++i) {
CUDA_SAFE_CALL(cudaSetDevice(i));
lstmLayers[i].setDevice(i);
lstmLayers[i].init(true);
}
Run Code Online (Sandbox Code Playgroud)
运行此程序会出现以下错误
terminate called after throwing an instance of 'thrust::system::system_error'
what(): driver shutting down
Run Code Online (Sandbox Code Playgroud)
请告诉我我的代码有什么问题以及如何正确执行?先谢谢你.