Which clone method should I use to create a deep copy of tensor

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);

Calling clone on the tensor sounds like the right approach. Could you describe the issues you are seeing using it?

data race still happened because I’m cloning tensorInputs while modifying it in the _impl.forward function. I got the error:

Thread 17: EXC_BAD_ACCESS (code=1, address=0x14a585000)

If you clone tensorInputs via:

at::Tensor tensorInputs = torch::from_blob((void*)wavBuffer, {1, bufLength}, at::kFloat).clone();

the object will stay alive until it gets out of scope.
I don’t understand how you are modifying it inside the forward method but maybe you want to clone it there so the object stays alive?