pytorch / extension-ffi

Examples of C extensions for PyTorch
258 stars 70 forks source link

C++ testing and validation #21

Open chenjun2hao opened 5 years ago

chenjun2hao commented 5 years ago

How can I be in c + + compiler environment, testing and validation. there the ‘THFloatTensor_data’ is not defined, when i use the code as follow:

int my_lib_add_forward(THFloatTensor *input1, THFloatTensor *input2,
               THFloatTensor *output)
{
  float * data_flat = THFloatTensor_data(input1);
}
ztianlin commented 4 years ago

Hi, you can try to write something like

include<torch/torch.h>

int my_lib_add_forward(at::Tensor input1, at::Tensor input2, at::Tensor output){ auto tmp = input1->contiguous(); float data_flat = tmp.data(); }

good luck