-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.cpp
More file actions
61 lines (54 loc) · 2.05 KB
/
main.cpp
File metadata and controls
61 lines (54 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// GPU acceleration and FP16 inference with timing
//
// Usage: example-gpu <model.safetensors> <vocab.txt> <audio.wav>
#include <parakeet/parakeet.hpp>
#include <chrono>
#include <iomanip>
#include <iostream>
int main(int argc, char *argv[]) {
if (argc != 4) {
std::cerr << "Usage: " << argv[0]
<< " <model.safetensors> <vocab.txt> <audio.wav>\n";
return 1;
}
// --- CPU baseline ---
std::cout << "=== CPU (FP32) ===\n";
{
parakeet::Transcriber t(argv[1], argv[2]);
auto start = std::chrono::high_resolution_clock::now();
auto result = t.transcribe(argv[3]);
auto elapsed = std::chrono::high_resolution_clock::now() - start;
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed)
.count();
std::cout << " Text: " << result.text << "\n";
std::cout << " Time: " << ms << " ms\n\n";
}
// --- GPU FP32 ---
std::cout << "=== GPU (FP32) ===\n";
{
parakeet::Transcriber t(argv[1], argv[2]);
t.to_gpu();
auto start = std::chrono::high_resolution_clock::now();
auto result = t.transcribe(argv[3]);
auto elapsed = std::chrono::high_resolution_clock::now() - start;
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed)
.count();
std::cout << " Text: " << result.text << "\n";
std::cout << " Time: " << ms << " ms\n\n";
}
// --- GPU FP16 ---
std::cout << "=== GPU (FP16) ===\n";
{
parakeet::Transcriber t(argv[1], argv[2]);
t.to_half(); // fp16 before gpu
t.to_gpu();
auto start = std::chrono::high_resolution_clock::now();
auto result = t.transcribe(argv[3]);
auto elapsed = std::chrono::high_resolution_clock::now() - start;
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed)
.count();
std::cout << " Text: " << result.text << "\n";
std::cout << " Time: " << ms << " ms\n";
}
return 0;
}