mirror of
https://github.com/NVIDIA/nvbench.git
synced 2026-04-29 19:21:14 +00:00
Move sleep kernel to its own header.
This will be useful for testing in general.
This commit is contained in:
@@ -3,28 +3,11 @@
|
|||||||
#include <nvbench/cuda_stream.cuh>
|
#include <nvbench/cuda_stream.cuh>
|
||||||
#include <nvbench/types.cuh>
|
#include <nvbench/types.cuh>
|
||||||
|
|
||||||
|
#include "sleep_kernel.cuh"
|
||||||
#include "test_asserts.cuh"
|
#include "test_asserts.cuh"
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
#include <cuda/std/chrono>
|
|
||||||
|
|
||||||
#include <cuda_runtime.h>
|
|
||||||
|
|
||||||
__global__ void sleep_kernel(double seconds)
|
|
||||||
{
|
|
||||||
const auto start = cuda::std::chrono::high_resolution_clock::now();
|
|
||||||
const auto ns = cuda::std::chrono::nanoseconds(
|
|
||||||
static_cast<nvbench::int64_t>(seconds * 1000 * 1000 * 1000));
|
|
||||||
const auto finish = start + ns;
|
|
||||||
|
|
||||||
auto now = cuda::std::chrono::high_resolution_clock::now();
|
|
||||||
while (now < finish)
|
|
||||||
{
|
|
||||||
now = cuda::std::chrono::high_resolution_clock::now();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_basic(cudaStream_t time_stream,
|
void test_basic(cudaStream_t time_stream,
|
||||||
cudaStream_t exec_stream,
|
cudaStream_t exec_stream,
|
||||||
bool expected)
|
bool expected)
|
||||||
|
|||||||
19
testing/sleep_kernel.cuh
Normal file
19
testing/sleep_kernel.cuh
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cuda/std/chrono>
|
||||||
|
|
||||||
|
#include <cuda_runtime.h>
|
||||||
|
|
||||||
|
__global__ void sleep_kernel(double seconds)
|
||||||
|
{
|
||||||
|
const auto start = cuda::std::chrono::high_resolution_clock::now();
|
||||||
|
const auto ns = cuda::std::chrono::nanoseconds(
|
||||||
|
static_cast<nvbench::int64_t>(seconds * 1000 * 1000 * 1000));
|
||||||
|
const auto finish = start + ns;
|
||||||
|
|
||||||
|
auto now = cuda::std::chrono::high_resolution_clock::now();
|
||||||
|
while (now < finish)
|
||||||
|
{
|
||||||
|
now = cuda::std::chrono::high_resolution_clock::now();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user