Dear Tejasvi,
You can use the predefined macro C_UDSI(c,t,i)[j], to define the gradients in direction you want. Here, i, is index of the scalar which identify the the number of the UDS you defined before. j is the direction which gradient is desired. j=0 is gradient in x direction, j=1 in y direction and j=2 in z direction. You can also use NV_MAG(C_UDSI_G(c,t,i)) to calculate the magnitude of the UDS gradient which is in turn a scalar quantity. Other information can be found in Fluent UDF manual specifically in UDS sections. Keep in mind that UDS gradient is defined only for cell threads and for wall (c0) and interior (c0,c1) faces you can use appropriate gradient macros.
I hope it helps