dgemm different results with and without print call

Hi, I’m a newbie in cuda programming. I’m using dgemm function in my code and I wanted to check the results of dgemm call via printing output array. I also print one of the input array before calling dgemm.
The interesting part is when print before and after calling dgemm everything works fine and arrays contain desired values. However, if I don’t print after calling dgemm, values of the input array become inf or nan(ind) in the next iteration.

My overall code is a simple multilayer perceptron and I’m using dgemm to calculate output unit values. In each propagation, I print some of arrays before calling dgemm. The part I could not understand is if I don’t print after calling dgemm, the values become inf or nan(ind). If I print the array after calling dgemm, everything works fine.