How to create a copy of tensorInputs
with the same values but different addresses for each data point in the following code? a search of the documentation brought me to many possible clone
methods, and none of them have detail documentation about how to use them.
The reason for clone is because I want to run the following code in a loop and I need to avoid data racing
at::Tensor tensorInputs = torch::from_blob((void*)wavBuffer, {1, bufLength}, at::kFloat);
float* floatInput = tensorInputs.data_ptr<float>();
if (!floatInput) {
return nil;
}
c10::InferenceMode guard;
CFTimeInterval startTime = CACurrentMediaTime();
auto result = _impl.forward({ tensorInputs }).toStringRef();
CFTimeInterval elapsedTime = CACurrentMediaTime() - startTime;
NSLog(@"inference time:%f", elapsedTime);
return [NSString stringWithCString:result.c_str() encoding:[NSString defaultCStringEncoding]];
I tried the following from this post and it doesn’t work:
tensorCopy = tensorInputs.detach().clone(LEGACY_CONTIGUOUS_MEMORY_FORMAT);