| 157 | } |
| 158 | |
| 159 | } // namespace |
| 160 | |
| 161 | void fill_torch_cuda_randn( |
| 162 | float * output, |
| 163 | size_t count, |
| 164 | uint64_t seed, |
| 165 | TorchRandnPrecision precision, |
| 166 | uint64_t start_index) { |
| 167 | if (output == nullptr && count != 0) { |
| 168 | throw std::invalid_argument("torch CUDA randn output pointer is null"); |
| 169 | } |
| 170 | for (size_t index = 0; index < count; ++index) { |
| 171 | float value = torch_cuda_randn_element(seed, start_index + static_cast<uint64_t>(index)); |
| 172 | if (precision == TorchRandnPrecision::BFloat16) { |
| 173 | value = round_to_bfloat16(value); |
| 174 | } |
| 175 | output[index] = value; |
| 176 | } |
| 177 | } |
| 178 | |