You don’t need to implement it using C/CUDA (but it will be definitely more efficient if you do so).
Here is one (untested) implementation for SmoothL1Loss using the functional interface:
def smooth_l1_loss(input, target):
    diff = input - target
    mask = diff.abs() < 1
    diff[mask] = diff[mask] ** 2
    return diff