我正在使用 SYCL 编写神经网络,但我对malloc_deviceSYCL 感到困惑。
template<typename T>
class Linear {
private:
T* weight;
T* input;
T* result;
T* bias;
T* dz;
const int M;
const int N;
const int K;
public:
Linear(T* x, T* r, int m, int n, intk, queue& Q): input(x), result(r), M(m), N(n), K(k) {
weight = malloc_device<T>(M * N, Q);
bias = malloc_device<T>(M, Q);
dz = malloc_device<T>(N * K, Q);
}
...
x = malloc_device<T>(N * K, Q),
r = malloc_device<T>(M * K, Q)
当我连续有多个Linears 时,所有实例都可以正确分配weightand bias。但是,只有最后一个Linear实例可以正确分配for dz,其他Linear实例分配失败dz并得到结果0。
有没有人可以解释为什么会发生?谢谢!