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

Integrate bitpack mappings into LLAMA #427

Merged
merged 6 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ if (LLAMA_BUILD_EXAMPLES)
add_subdirectory("examples/viewcopy")
add_subdirectory("examples/bufferguard")
add_subdirectory("examples/raycast")
add_subdirectory("examples/bitpack")
add_subdirectory("examples/bytesplit")
add_subdirectory("examples/floatpack")
add_subdirectory("examples/bitpackint")
add_subdirectory("examples/bitpackfloat")

# alpaka examples
find_package(alpaka 0.7.0 QUIET)
Expand Down
151 changes: 0 additions & 151 deletions examples/bitpack/bitpack.cpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cmake_minimum_required (VERSION 3.15)
project(llama-floatpack CXX)
project(llama-bitpackfloat CXX)

if (NOT TARGET llama::llama)
find_package(llama REQUIRED)
endif()
add_executable(${PROJECT_NAME} floatpack.cpp)
add_executable(${PROJECT_NAME} bitpackfloat.cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
target_link_libraries(${PROJECT_NAME} PRIVATE llama::llama)
54 changes: 54 additions & 0 deletions examples/bitpackfloat/bitpackfloat.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <fmt/core.h>
#include <llama/llama.hpp>
#include <random>

// clang-format off
namespace tag
{
struct X{};
struct Y{};
} // namespace tag

using Vector = llama::Record<
llama::Field<tag::X, double>,
llama::Field<tag::Y, double>
>;
// clang-format on

auto main() -> int
{
constexpr auto N = 100;
constexpr auto exponentBits = 5;
constexpr auto mantissaBits = 13;
const auto mapping
= llama::mapping::BitPackedFloatSoA{exponentBits, mantissaBits, llama::ArrayExtents<llama::dyn>{N}, Vector{}};

auto view = llama::allocView(mapping);

boost::mp11::mp_for_each<boost::mp11::mp_iota_c<decltype(mapping)::blobCount>>(
[&](auto ic)
{
fmt::print(
"Blob {}: {} bytes (uncompressed {} bytes)\n",
ic,
mapping.blobSize(ic),
N * sizeof(llama::GetType<Vector, llama::RecordCoord<decltype(ic)::value>>));
});

std::default_random_engine engine;
std::uniform_real_distribution dist{0.0f, 100.0f};

// view(0)(tag::X{}) = -123.456789f;
// float f = view(0)(tag::X{});
// fmt::print("{}", f);

for(std::size_t i = 0; i < N; i++)
{
const auto v = dist(engine);
view(i)(tag::X{}) = v;
view(i)(tag::Y{}) = -v;

fmt::print("{:11} -> {:11}\n", v, static_cast<float>(view(i)(tag::X{})));
fmt::print("{:11} -> {:11}\n", -v, static_cast<float>(view(i)(tag::Y{})));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cmake_minimum_required (VERSION 3.15)
project(llama-bitpack CXX)
project(llama-bitpackint CXX)

if (NOT TARGET llama::llama)
find_package(llama REQUIRED)
endif()
add_executable(${PROJECT_NAME} bitpack.cpp)
add_executable(${PROJECT_NAME} bitpackint.cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
target_link_libraries(${PROJECT_NAME} PRIVATE llama::llama)
66 changes: 66 additions & 0 deletions examples/bitpackint/bitpackint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <cstdint>
#include <fmt/core.h>
#include <llama/llama.hpp>

// clang-format off
namespace tag
{
struct X{};
struct Y{};
struct Z{};
} // namespace tag

using Vector = llama::Record<
llama::Field<tag::X, std::uint16_t>,
llama::Field<tag::Y, std::int32_t>,
llama::Field<tag::Z, std::uint64_t>
>;
// clang-format on

auto main() -> int
{
constexpr auto N = 128;
constexpr auto bits = 7;
const auto mapping = llama::mapping::BitPackedIntSoA<llama::ArrayExtentsDynamic<1>, Vector>{bits, {N}};

auto view = llama::allocView(mapping);

boost::mp11::mp_for_each<boost::mp11::mp_iota_c<decltype(mapping)::blobCount>>(
[&](auto ic)
{
fmt::print(
"Blob {}: {} bytes (uncompressed {} bytes)\n",
ic,
mapping.blobSize(ic),
N * sizeof(llama::GetType<Vector, llama::RecordCoord<decltype(ic)::value>>));
});

for(std::size_t i = 0; i < N; i++)
{
view(i)(tag::X{}) = i;
view(i)(tag::Y{}) = -static_cast<std::int32_t>(i); // cut-off of sign bits after -64
view(i)(tag::Z{}) = i * 2; // exceeds bits
}

fmt::print("Bitpacked initial:\n");
for(std::size_t i = 0; i < N; i++)
fmt::print("[{}, {}, {}]\n", view(i)(tag::X{}), view(i)(tag::Y{}), view(i)(tag::Z{}));

// extract into a view of full size integers
auto viewExtracted
= llama::allocViewUninitialized(llama::mapping::AoS<llama::ArrayExtents<llama::dyn>, Vector>{{N}});
llama::copy(view, viewExtracted);
if(!std::equal(view.begin(), view.end(), viewExtracted.begin(), viewExtracted.end()))
fmt::print("ERROR: unpacked view is different\n");

// compute something on the extracted view
for(std::size_t i = 0; i < N; i++)
viewExtracted(i) = viewExtracted(i) % 10;

// compress back
llama::copy(viewExtracted, view);

fmt::print("Bitpacked after % 10:\n");
for(std::size_t i = 0; i < N; i++)
fmt::print("[{}, {}, {}]\n", view(i)(tag::X{}), view(i)(tag::Y{}), view(i)(tag::Z{}));
}
83 changes: 0 additions & 83 deletions examples/common/IntegralReference.hpp

This file was deleted.

Loading