Hi,
For lossless encoding/decoding, please refer to this post:
Can tx2nx decode YUV444? - #3 by DaneLLL
The supported format is YUV444. GRAY8 is actually the Y plane of YUV444. So a possible solution is to put GRAY8 data into Y plane and not to use the U, V planes. So that you can encode into lossless h265 stream. After decoding, can extract only Y plane from YUV444 to get the GRAY8 data.