@@ -23,9 +23,9 @@ limitations under the License.
2323
2424namespace tensorflow {
2525
26- static Graph* SparseXent (int batch_size, int num_classes) {
26+ static Graph* SparseXent (int batch_size, int num_classes, DataType value_type ) {
2727 Graph* g = new Graph (OpRegistry::Global ());
28- Tensor logits (DT_FLOAT , TensorShape ({batch_size, num_classes}));
28+ Tensor logits (value_type , TensorShape ({batch_size, num_classes}));
2929 logits.flat <float >().setRandom ();
3030 Tensor labels (DT_INT64 , TensorShape ({batch_size}));
3131 std::random_device rd;
@@ -41,44 +41,45 @@ static Graph* SparseXent(int batch_size, int num_classes) {
4141 return g;
4242}
4343
44- #define BM_SparseXentDev (BATCH, CLASS, DEVICE ) \
45- static void BM_SparseXent##_##BATCH ##_##CLASS ##_##DEVICE ( \
44+ #define BM_SparseXentDev (BATCH, CLASS, DEVICE, DTYPE ) \
45+ static void BM_SparseXent##_##BATCH ##_##CLASS ##_##DEVICE ##_## DTYPE ( \
4646 ::testing::benchmark::State& state) { \
47- test::Benchmark (#DEVICE , SparseXent (BATCH , CLASS ), \
47+ test::Benchmark (#DEVICE , SparseXent (BATCH , CLASS , DTYPE ), \
4848 /* old_benchmark_api*/ false ) \
4949 .Run (state); \
5050 state.SetItemsProcessed (static_cast <int64>(state.iterations ()) * BATCH * \
5151 CLASS ); \
5252 } \
53- BENCHMARK (BM_SparseXent##_##BATCH ##_##CLASS ##_##DEVICE );
53+ BENCHMARK (BM_SparseXent##_##BATCH ##_##CLASS ##_##DEVICE ##_##DTYPE );
54+
55+ #define BM_SPARSE_XENT_DEV_CPU (DTYPE ) \
56+ BM_SparseXentDev (8 , 1000000 , cpu, DTYPE ); \
57+ BM_SparseXentDev (16 , 10000 , cpu, DTYPE ); \
58+ BM_SparseXentDev (16 , 100000 , cpu, DTYPE ); \
59+ BM_SparseXentDev (32 , 10000 , cpu, DTYPE ); \
60+ BM_SparseXentDev (32 , 100000 , cpu, DTYPE ); \
61+ BM_SparseXentDev (64 , 10000 , cpu, DTYPE ); \
62+ BM_SparseXentDev (64 , 100000 , cpu, DTYPE );
63+
64+ // CPU
65+ BM_SPARSE_XENT_DEV_CPU (DT_FLOAT );
66+ BM_SPARSE_XENT_DEV_CPU (DT_BFLOAT16 );
5467
5568// / The representative tests for ptb_word on GPU
5669#if GOOGLE_CUDA || TENSORFLOW_USE_ROCM
57- BM_SparseXentDev (8 , 1000000 , gpu);
70+ BM_SparseXentDev (8 , 1000000 , gpu, DT_FLOAT );
5871
59- BM_SparseXentDev (16 , 10000 , gpu);
60- BM_SparseXentDev (16 , 30000 , gpu);
61- BM_SparseXentDev (16 , 100000 , gpu);
72+ BM_SparseXentDev (16 , 10000 , gpu, DT_FLOAT );
73+ BM_SparseXentDev (16 , 30000 , gpu, DT_FLOAT );
74+ BM_SparseXentDev (16 , 100000 , gpu, DT_FLOAT );
6275
63- BM_SparseXentDev (32 , 10000 , gpu);
64- BM_SparseXentDev (32 , 30000 , gpu);
65- BM_SparseXentDev (32 , 100000 , gpu);
76+ BM_SparseXentDev (32 , 10000 , gpu, DT_FLOAT );
77+ BM_SparseXentDev (32 , 30000 , gpu, DT_FLOAT );
78+ BM_SparseXentDev (32 , 100000 , gpu, DT_FLOAT );
6679
67- BM_SparseXentDev (64 , 10000 , gpu);
68- BM_SparseXentDev (64 , 30000 , gpu);
69- BM_SparseXentDev (64 , 100000 , gpu);
80+ BM_SparseXentDev (64 , 10000 , gpu, DT_FLOAT );
81+ BM_SparseXentDev (64 , 30000 , gpu, DT_FLOAT );
82+ BM_SparseXentDev (64 , 100000 , gpu, DT_FLOAT );
7083#endif // GOOGLE_CUDA || TENSORFLOW_USE_ROCM
7184
72- // CPU
73- BM_SparseXentDev (8 , 1000000 , cpu);
74-
75- BM_SparseXentDev (16 , 10000 , cpu);
76- BM_SparseXentDev (16 , 100000 , cpu);
77-
78- BM_SparseXentDev (32 , 10000 , cpu);
79- BM_SparseXentDev (32 , 100000 , cpu);
80-
81- BM_SparseXentDev (64 , 10000 , cpu);
82- BM_SparseXentDev (64 , 100000 , cpu);
83-
8485} // end namespace tensorflow
0 commit comments