def run_tests(self): from kaldi.cudamatrix import cuda_available if cuda_available(): from kaldi.cudamatrix import CuDevice CuDevice.instantiate().set_debug_stride_mode(True) CuDevice.instantiate().select_gpu_id("yes") super(test_cuda, self).run_tests() CuDevice.instantiate().print_profile() else: print("CUDA not available. Running tests on CPU.") super(test_cuda, self).run_tests()
def testCuVectorGetItem(self): v = CuVector() with self.assertRaises(IndexError): v[0] v = CuVector.new([3, 5, 7, 11, 13]) self.assertAlmostEqual(3.0, v[0]) self.assertAlmostEqual(7.0, v[2]) self.assertAlmostEqual(13.0, v[4]) with self.assertRaises(IndexError): v[5] if __name__ == '__main__': if cuda_available(): from kaldi.cudamatrix import CuDevice for i in range(2): CuDevice.instantiate().set_debug_stride_mode(True) if i == 0: CuDevice.instantiate().select_gpu_id("no") else: CuDevice.instantiate().select_gpu_id("yes") unittest.main() CuDevice.instantiate().print_profile() else: unittest.main()
#!/usr/bin/env python from __future__ import print_function from kaldi.asr import NnetLatticeFasterBatchRecognizer from kaldi.decoder import LatticeFasterDecoderOptions from kaldi.nnet3 import NnetBatchComputerOptions from kaldi.util.table import SequentialMatrixReader from kaldi.cudamatrix import cuda_available if cuda_available(): from kaldi.cudamatrix import CuDevice CuDevice.instantiate().select_gpu_id('yes') CuDevice.instantiate().allow_multithreading() # Construct recognizer decoder_opts = LatticeFasterDecoderOptions() decoder_opts.beam = 13 decoder_opts.max_active = 7000 compute_opts = NnetBatchComputerOptions() compute_opts.acoustic_scale = 1.0 compute_opts.frame_subsampling_factor = 3 compute_opts.frames_per_chunk = 150 asr = NnetLatticeFasterBatchRecognizer.from_files( "final.mdl", "HCLG.fst", "words.txt", decoder_opts=decoder_opts, compute_opts=compute_opts, num_threads=4) # Define feature pipelines as Kaldi rspecifiers feats_rspec = "ark:compute-mfcc-feats --config=mfcc.conf scp:wav.scp ark:- |" ivectors_rspec = ( "ark:compute-mfcc-feats --config=mfcc.conf scp:wav.scp ark:-"
matrices[matrix].resize(0, 0) gflops = num_floats_processed / (tim.elapsed() * 1.0e9) print( "For CuMatrix::Reize float, for size multiple {}, speed was {} gigaflops" .format(size_multiple, gflops)) def testCudaMatrixResize(): sizes = [1, 2, 4, 8, 16, 32] for s in sizes: aux(s) if __name__ == '__main__': if cuda_available(): from kaldi.cudamatrix import CuDevice for loop in range(2): CuDevice.Instantiate().SetDebugStrideMode(True) if loop == 0: CuDevice.Instantiate().SelectGpuId("no") else: CuDevice.Instantiate().SelectGpuId("yes") testCudaMatrixResize() CuDevice.Instantiate().PrintProfile() else: testCudaMatrixResize()