Thank you for your advice.
The C-implementation way is little tricky, for I found the pytorch->torch->Aten->CUDNN dependency chain,, which I am not good at.
The autograd way looks easy. But I have to use for loop to implement it. Well, I will try, thank you.