/* * Copyright (c) Facebook, Inc. and its affiliates. * All rights reserved. * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ #include "BenchUtils.h" #include #include #include #ifdef _OPENMP #include #endif namespace fbgemm { std::default_random_engine eng; template void randFill(aligned_vector& vec, T low, T high, std::true_type) { std::uniform_int_distribution dis(low, high); std::generate(vec.begin(), vec.end(), [&] { return dis(eng); }); } template void randFill(aligned_vector& vec, T low, T high, std::false_type) { std::uniform_real_distribution dis(low, high); std::generate(vec.begin(), vec.end(), [&] { return dis(eng); }); } template void randFill(aligned_vector& vec, T low, T high) { randFill(vec, low, high, std::is_integral()); } template void randFill(aligned_vector& vec, float low, float high); template void randFill(aligned_vector& vec, uint8_t low, uint8_t high); template void randFill(aligned_vector& vec, int8_t low, int8_t high); template void randFill(aligned_vector& vec, int low, int high); void llc_flush(std::vector& llc) { volatile char* data = llc.data(); for (int i = 0; i < llc.size(); i++) { data[i]++; } } int fbgemm_get_num_threads() { #if defined(FBGEMM_MEASURE_TIME_BREAKDOWN) || !defined(_OPENMP) return 1; #else return omp_get_num_threads(); #endif } int fbgemm_get_thread_num() { #if defined(FBGEMM_MEASURE_TIME_BREAKDOWN) || !defined(_OPENMP) return 0; #else return omp_get_thread_num(); #endif } } // namespace fbgemm