Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing black scholes to float and improving performance #840

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions examples/black_scholes.cu
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ public:
auto r = r_(idx);

auto VsqrtT = V * sqrt(T);
auto d1 = (log(S / K) + (r + 0.5 * V * V) * T) / VsqrtT ;
auto d1 = (log(S / K) + (r + 0.5f * V * V) * T) / VsqrtT ;
auto d2 = d1 - VsqrtT;
auto cdf_d1 = normcdf(d1);
auto cdf_d2 = normcdf(d2);
auto expRT = exp(-1 * r * T);
auto cdf_d1 = normcdff(d1); // Note in a custom op we call the CUDA math function directly
auto cdf_d2 = normcdff(d2);
auto expRT = exp(-1.f * r * T);

out_(idx) = S * cdf_d1 - K * expRT * cdf_d2;
}
Expand All @@ -96,11 +96,11 @@ void compute_black_scholes_matx(tensor_t<T1,1>& K,
cudaExecutor& exec)
{
auto VsqrtT = V * sqrt(T);
auto d1 = (log(S / K) + (r + 0.5 * V * V) * T) / VsqrtT ;
auto d1 = (log(S / K) + (r + 0.5f * V * V) * T) / VsqrtT ;
auto d2 = d1 - VsqrtT;
auto cdf_d1 = normcdf(d1);
auto cdf_d2 = normcdf(d2);
auto expRT = exp(-1 * r * T);
auto expRT = exp(-1.f * r * T);

(output = S * cdf_d1 - K * expRT * cdf_d2).run(exec);
}
Expand All @@ -109,7 +109,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
{
MATX_ENTER_HANDLER();

using dtype = double;
using dtype = float;

index_t input_size = 100000000;
constexpr uint32_t num_iterations = 1;
Expand Down