-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better float testing support and fix of float pow
- Loading branch information
1 parent
6946b31
commit 81c4053
Showing
7 changed files
with
113 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "tests_powf.h" | ||
#include "tests.h" | ||
|
||
#include <cuinterval/interval.h> | ||
|
||
#include <array> | ||
#include <source_location> | ||
#include <vector> | ||
|
||
using cu::interval; | ||
|
||
std::vector<interval<float>> compute_powf(cudaStream_t stream, std::vector<interval<float>> xs, std::vector<int> exponents); | ||
|
||
void tests_powf(cudaStream_t stream, cudaEvent_t event) | ||
{ | ||
using T = float; | ||
using I = interval<T>; | ||
|
||
using namespace boost::ut; | ||
|
||
constexpr int n = 5; | ||
constexpr int max_ulp_diff = 4; | ||
std::vector<I> xs = { { -1.0, 0.0 }, { 0.0, 1.0 }, { 1.0, 2.0 }, { 2.0, 3.0 }, { 3.0, 4.0 } }; | ||
std::vector<int> exponents = { 0, 1, 2, 3, 4 }; | ||
std::vector<I> out = compute_powf(stream, xs, exponents); | ||
std::array<I, n> ref { I { 1.0, 1.0 }, { 0.0, 1.0 }, { 1.0, 4.0 }, { 8.0, 27.0 }, { 81.0, 256.0 } }; | ||
|
||
check_all_equal<I, n>(out.data(), ref, max_ulp_diff, std::source_location::current(), xs.data(), exponents.data()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <cuinterval/cuinterval.h> | ||
|
||
#include <thrust/copy.h> | ||
#include <thrust/device_vector.h> | ||
#include <thrust/host_vector.h> | ||
#include <thrust/transform.h> | ||
|
||
#include <vector> | ||
|
||
using cu::interval; | ||
|
||
struct powf_fn | ||
{ | ||
template<typename I> | ||
__device__ I operator()(const I &x, int n) const | ||
{ | ||
using cu::pow; | ||
return pow(x, n); | ||
} | ||
}; | ||
|
||
std::vector<interval<float>> compute_powf(cudaStream_t stream, std::vector<interval<float>> xs, std::vector<int> exponents) | ||
{ | ||
using T = float; | ||
using I = interval<T>; | ||
|
||
thrust::host_vector<I> h_xs = xs; | ||
thrust::host_vector<int> h_exponents = exponents; | ||
|
||
auto n = xs.size(); | ||
thrust::device_vector<I> d_res(n); | ||
thrust::device_vector<I> d_xs = h_xs; | ||
thrust::device_vector<int> d_exponents = h_exponents; | ||
thrust::transform(d_xs.begin(), d_xs.end(), d_exponents.begin(), d_res.begin(), powf_fn()); | ||
std::vector<I> h_res(n); | ||
thrust::copy(d_res.begin(), d_res.end(), h_res.begin()); | ||
|
||
return h_res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
#ifndef CUDA_INTERVAL_TESTS_POWF_H | ||
#define CUDA_INTERVAL_TESTS_POWF_H | ||
|
||
#include <cuda_runtime.h> | ||
|
||
void tests_powf(cudaStream_t stream, cudaEvent_t event); | ||
|
||
#endif // CUDA_INTERVAL_TESTS_POWF_H |