I think I would need to see your (slow) loop approach or any other references.
The previous post:
>>> res[0]
tensor([  0,   1,   2,   3,   8,   9,  10,  11,  16,  17,  18,  19,  24,  25,
         26,  27,  64,  65,  66,  67,  72,  73,  74,  75,  80,  81,  82,  83,
         88,  89,  90,  91, 128, 129, 130, 131, 136, 137, 138, 139, 144, 145,
        146, 147, 152, 153, 154, 155])

would just work, if you use:
x = torch.arange(3* 8* 8).reshape((3,8,8))
out = x.view(-1)
print(out)

although your output is missing some values.