在下面的代码中,我绝对需要在 GPU 中执行完整的功能,而不需要一次跳转回 CPU。这是因为我有 4 个 CPU 内核,但我有 1200 个 cuda 内核。从理论上讲,这是可能的,因为 tensorflow feed_forwards、if 语句和变量分配可以在 GPU 上完成(我有 NVIDIA GTX 1060)。
我面临的问题是 tensorflow2.0 在后端自动分配给 GPU 和 CPU,但没有提到它的哪些操作与 GPU 兼容。当我使用设备作为 GPU 运行以下函数时,我得到
parallel_func could not be transformed and will be staged without change.
Run Code Online (Sandbox Code Playgroud)
它在 GPU 上按顺序运行。
我的问题是在哪里使用 tf.device?哪一部分代码会被签名转换成 GPU 代码,什么会留在 CPU 上?我怎样才能将其转换为 GPU?
@tf.function
def parallel_func(self):
for i in tf.range(114): #want this parallel on GPU
for count in range(320): #want this sequential on GPU
retrivedValue = self.data[i][count]
if self.var[i]==1:
self.value[i] = retrievedValue …Run Code Online (Sandbox Code Playgroud) @app.route("/")
def index():
return render_template("webpage.html")
Run Code Online (Sandbox Code Playgroud)
我的 FlaskPage.py 文件中有上述函数,我想从下面显示的“返回主页”按钮到上面的根 URL 建立一个链接。但是,url_for 不接受空字符串作为参数,并抛出错误,如下所示
<button formaction="{{ url_for('') }}">Back to Home</button>
Run Code Online (Sandbox Code Playgroud)
错误
Could not build url for endpoint ''
Run Code Online (Sandbox Code Playgroud)
提前致谢。