给定具有形状的多维数组[A][B][C][D]但存储为具有长度的1-dim数组[A*B*C*D].我想使用模板元编程来简化索引计算.指数(a,b,c,d)应该在位置
a*B*C*D + b*C*D + c*D + d
Run Code Online (Sandbox Code Playgroud)
我目前正在使用
#include <iostream>
#include <cstdlib>
#include <array>
template<size_t start, size_t AXES>
struct prod_func
{
constexpr inline size_t operator()(const std::array<const size_t, AXES> arr) const
{
return arr[start] * prod_func < start + 1, AXES > ()(arr);
}
} ;
template<size_t AXES>
struct prod_func<AXES, AXES>
{
constexpr inline size_t operator()(const std::array<const size_t, AXES> arr) const
{
return 1;
}
} ;
template<int AXES>
class index
{
const std::array<const …Run Code Online (Sandbox Code Playgroud) c++ arrays template-meta-programming variadic-templates c++11
有一种方法OpKernel
// Returns true iff this op kernel is considered "expensive". The
// runtime may use this flag to optimize graph execution for example
// to "inline" inexpensive kernels.
virtual bool IsExpensive() { return expensive_; }
Run Code Online (Sandbox Code Playgroud)
似乎默认情况下GPU上的所有操作都被认为是便宜的,而CPU,SYSL被标记为昂贵.
要弄清楚它的定义和效果有点难expensive.指南中没有信息.
IsExpensive应该有什么具体的指导方针false, true?AsyncOp(像RemoteFusedGraphExecuteOp)昂贵,MPIAllgatherOp似乎被定义为不昂贵.这不是矛盾吗?我问,因为IdentityOp明确标记为便宜.我想知道,如果我应该在我的自定义操作中覆盖此方法,因为每个CPU版本(甚至任何自定义代码)都被标记为昂贵.
XLA的整个逻辑似乎是关于指令是否昂贵.所以它可能是一个需要考虑的重要部分.因此,关于真/假的抛硬币可能不是决定我的自定义操作中的返回值的最佳方法.
我能得到的最接近的例子是这个问题:https://github.com/tensorflow/tensorflow/issues/899
使用此最小可重现代码:
import tensorflow as tf
import tensorflow.python.framework.ops as ops
g = tf.Graph()
with g.as_default():
A = tf.Variable(tf.random_normal( [25,16] ))
B = tf.Variable(tf.random_normal( [16,9] ))
C = tf.matmul(A,B) # shape=[25,9]
for op in g.get_operations():
flops = ops.get_stats_for_node_def(g, op.node_def, 'flops').value
if flops is not None:
print 'Flops should be ~',2*25*16*9
print '25 x 25 x 9 would be',2*25*25*9 # ignores internal dim, repeats first
print 'TF stats gives',flops
Run Code Online (Sandbox Code Playgroud)
但是,返回的FLOPS始终为None.有没有办法具体测量FLOPS,尤其是PB文件?
我知道[1]。通过几行代码,我只想从CPU使用率最高的前n个进程中提取当前的CPU使用率。或多或少都是前5排的顶部。使用github.com/shirou/gopsutil/process这很简单:
// file: gotop.go
package main
import (
"log"
"time"
"sort"
"github.com/shirou/gopsutil/process"
)
type ProcInfo struct{
Name string
Usage float64
}
type ByUsage []ProcInfo
func (a ByUsage) Len() int { return len(a) }
func (a ByUsage) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByUsage) Less(i, j int) bool {
return a[i].Usage > a[j].Usage
}
func main() {
for {
processes, _ := process.Processes()
var procinfos []ProcInfo
for _, p …Run Code Online (Sandbox Code Playgroud) 我安装了 Tensorflow 和 Anaconda。现在我想在 R 中使用它,我需要重新安装 Tensorflow,因为这里的注释
注意:您不应将 TensorFlow 与 Anaconda 一起安装,因为 Anaconda 构建 Python 共享库的方式存在问题,会阻止来自 R 的动态链接。
我已经尝试从 Anaconda 卸载并使用 pip 安装,但它到达 anaconda 目录中的同一位置。Tesorflow 正在从终端运行,但在 R 中显示Error: Command failed (1)
任何人都可以帮助我如何解决这个问题?我应该卸载 anaconda 并使用 pip 安装 Tensorflow 吗?
我想通过Tensorflow计算Jacobian矩阵。
是)我有的:
def compute_grads(fn, vars, data_num):
grads = []
for n in range(0, data_num):
for v in vars:
grads.append(tf.gradients(tf.slice(fn, [n, 0], [1, 1]), v)[0])
return tf.reshape(tf.stack(grads), shape=[data_num, -1])
Run Code Online (Sandbox Code Playgroud)
fn是损失函数,vars都是可训练的变量,并且data_num是许多数据。
但是,如果我们增加数据数量,则需要花费大量时间来运行该功能compute_grads。有任何想法吗?