如果虚拟函数表对于类的所有对象都是相同的,那么为什么指向该表的指针(vfptr)不能是静态的并且在所有对象之间共享?
我正在比较使用 pytorch 和 onnxruntime 的输入的推理时间,我发现 onnxruntime 在 GPU 上实际上较慢,而在 CPU 上则明显更快
我在 Windows 10 上尝试过这个。
相关代码-
import torch
from torchvision import models
import onnxruntime # to inference ONNX models, we use the ONNX Runtime
import onnx
import os
import time
batch_size = 1
total_samples = 1000
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
def …Run Code Online (Sandbox Code Playgroud) class A
{
public:
int x;
//create a vector of functors in B and C here
};
class B
{
public:
struct bFunctor
{
void operator()() const
{
//some code
}
};
};
class C
{
public:
struct cFunctor
{
void operator()() const
{
//some code
}
};
};
void main()
{
A obj;
//iterate through the vector in A and call the functors in B and C
}
Run Code Online (Sandbox Code Playgroud)
我的问题是什么应该是格式vector类A调用functors中B和C?或者是,这是有可能有一个基础的唯一途径 …