Skip to content

Adding Hardware acceleration version of Queries 1 and 8 in csharp #274

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
14 changes: 2 additions & 12 deletions benchmark/csharp/Tpch/Tpch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netcoreapp3.1</TargetFrameworks>
<RootNamespace>Tpch</RootNamespace>
<AssemblyName>Tpch</AssemblyName>
Expand All @@ -11,7 +11,6 @@
<ItemGroup>
<!-- Workaround https://github.com/dotnet/project-system/issues/935 -->
<None Include="**/*.cs" />

<ProjectReference Include="..\..\..\src\csharp\Microsoft.Spark.Experimental\Microsoft.Spark.Experimental.csproj" />
<ProjectReference Include="..\..\..\src\csharp\Microsoft.Spark\Microsoft.Spark.csproj" />
</ItemGroup>
Expand All @@ -21,16 +20,7 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<Compile Remove="VectorFunctions.cs" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Compile Remove="VectorFunctions.intrinsics.cs" />
</ItemGroup>
</Otherwise>
</Choose>

</Project>
53 changes: 40 additions & 13 deletions benchmark/csharp/Tpch/TpchFunctionalQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,8 @@ internal void Q1()
.Show();
}

internal void Q1v()
{
Func<Column, Column, Column> discPrice = VectorUdf<DoubleArray, DoubleArray, DoubleArray>(
(price, discount) => VectorFunctions.ComputeDiscountPrice(price, discount));

Func<Column, Column, Column, Column> total = VectorUdf<DoubleArray, DoubleArray, DoubleArray, DoubleArray>(
(price, discount, tax) => VectorFunctions.ComputeTotal(price, discount, tax));

internal void Q1aCommon(Func<Column, Column, Column> discPrice, Func<Column, Column, Column, Column> total)
{
_lineitem.Filter(Col("l_shipdate") <= "1998-09-02")
.GroupBy(Col("l_returnflag"), Col("l_linestatus"))
.Agg(Sum(Col("l_quantity")).As("sum_qty"), Sum(Col("l_extendedprice")).As("sum_base_price"),
Expand All @@ -82,6 +76,28 @@ internal void Q1v()
.Show();
}

internal void Q1a()
{
Func<Column, Column, Column> discPrice = VectorUdf<DoubleArray, DoubleArray, DoubleArray>(
(price, discount) => VectorFunctions.ComputeDiscountPrice(price, discount));

Func<Column, Column, Column, Column> total = VectorUdf<DoubleArray, DoubleArray, DoubleArray, DoubleArray>(
(price, discount, tax) => VectorFunctions.ComputeTotal(price, discount, tax));

Q1aCommon(discPrice, total);
}

internal void Q1ha()
{
Func<Column, Column, Column> discPrice = VectorUdf<DoubleArray, DoubleArray, DoubleArray>(
(price, discount) => VectorFunctionsIntrinsics.ComputeDiscountPrice(price, discount));

Func<Column, Column, Column, Column> total = VectorUdf<DoubleArray, DoubleArray, DoubleArray, DoubleArray>(
(price, discount, tax) => VectorFunctionsIntrinsics.ComputeTotal(price, discount, tax));

Q1aCommon(discPrice, total);
}

internal void Q2()
{
DataFrame europe = _region.Filter(Col("r_name") == "EUROPE")
Expand Down Expand Up @@ -227,12 +243,9 @@ internal void Q8()
.Show();
}

internal void Q8v()
internal void Q8aCommon(Func<Column, Column, Column> discPrice)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't Q8 call this as well?

{
Func<Column, Column> getYear = Udf<string, string>(x => x.Substring(0, 4));
Func<Column, Column, Column> discPrice = VectorUdf<DoubleArray, DoubleArray, DoubleArray>(
(price, discount) => VectorFunctions.ComputeDiscountPrice(price, discount));

Func<Column, Column> getYear = Udf<string, string>(x => x.Substring(0, 4));
Func<Column, Column, Column> isBrazil = Udf<string, double, double>((x, y) => x == "BRAZIL" ? y : 0);

DataFrame fregion = _region.Filter(Col("r_name") == "AMERICA");
Expand Down Expand Up @@ -261,6 +274,20 @@ internal void Q8v()
.Show();
}

internal void Q8a()
{
Func<Column, Column, Column> discPrice = VectorUdf<DoubleArray, DoubleArray, DoubleArray>(
(price, discount) => VectorFunctions.ComputeDiscountPrice(price, discount));
Q8aCommon(discPrice);
}

internal void Q8ha()
{
Func<Column, Column, Column> discPrice = VectorUdf<DoubleArray, DoubleArray, DoubleArray>(
(price, discount) => VectorFunctionsIntrinsics.ComputeDiscountPrice(price, discount));
Q8aCommon(discPrice);
}

internal void Q9()
{
Func<Column, Column> getYear = Udf<string, string>(x => x.Substring(0, 4));
Expand Down
2 changes: 1 addition & 1 deletion benchmark/csharp/Tpch/VectorFunctions.intrinsics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Tpch
{
internal static class VectorFunctions
internal static class VectorFunctionsIntrinsics
{
internal static unsafe DoubleArray ComputeTotal(DoubleArray price, DoubleArray discount, DoubleArray tax)
{
Expand Down