| 34 | |
| 35 | #ifdef USE_CUDNN |
| 36 | TEST(OperationBenchmark, CrossEntropyFwd) { |
| 37 | auto cuda = std::make_shared<singa::CudaGPU>(); |
| 38 | auto ctx = cuda->context(0); |
| 39 | int bs = 64; |
| 40 | int dim = 10; |
| 41 | vector<DataType> dtypes = {kFloat16, kFloat32}; |
| 42 | |
| 43 | Tensor t(Shape{bs}, cuda); |
| 44 | t.SetValue(0.0f); |
| 45 | t = t.AsType(kInt); |
| 46 | |
| 47 | for (auto dtype : dtypes) { |
| 48 | Tensor p(Shape{bs, dim}, cuda, dtype); |
| 49 | Uniform(0.0f, 1.0f, &p); |
| 50 | |
| 51 | high_resolution_clock::time_point t1 = high_resolution_clock::now(); |
| 52 | |
| 53 | for (int i = 0; i < 1000; ++i) { |
| 54 | auto l = CrossEntropyFwd(p, t); |
| 55 | cudaStreamSynchronize(cuda->context(0)->stream); |
| 56 | } |
| 57 | |
| 58 | high_resolution_clock::time_point t2 = high_resolution_clock::now(); |
| 59 | duration<double> time_span = duration_cast<duration<double>>(t2 - t1); |
| 60 | cout << " dtype " << dtype; |
| 61 | cout << " - " << time_span.count() << " sec"; |
| 62 | cout << endl; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | TEST(OperationBenchmark, Mult) { |
| 67 | auto cuda = std::make_shared<singa::CudaGPU>(); |
nothing calls this directly
no test coverage detected