The threshold operation is not differentiable, so you are detaching the result from the computation graph:
SR = torch.randn(10, 10, requires_grad=True)
SR = (SR > 0.5).float() 
print(SR.requires_grad)
> False

You could take at e.g. the kornia implementation of dice loss 3 and reuse it.