Skip to content

Commit 83e22b5

Browse files
committed
implemented parts of reader
0 parents  commit 83e22b5

11 files changed

+429
-0
lines changed

.clang-format

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: 2024 Binsparse Developers
2+
#
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
5+
---
6+
BasedOnStyle: LLVM
7+
PointerAlignment: Left
8+
ColumnLimit: 80
9+
AlwaysBreakTemplateDeclarations: Yes
10+
AllowShortFunctionsOnASingleLine: Empty
11+
SpaceAfterCStyleCast: true
12+
---

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
scripts
2+
venv
3+
build
4+
._*
5+
tensor_test_files

CMakeLists.txt

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
include(FetchContent)
2+
3+
cmake_minimum_required(VERSION 3.5)
4+
project(bsp-to-taco)
5+
6+
add_library(bsp-to-taco SHARED)
7+
8+
cmake_policy(SET CMP0079 NEW)
9+
10+
set(CMAKE_C_STANDARD 11)
11+
12+
#set(CMAKE_CXX_STANDARD 20)
13+
14+
#set(CMAKE_C_FLAGS "-O3 -march=native")
15+
set(CMAKE_CXX_FLAGS "-O3 -march=native -Wall -Wno-narrowing -fPIC")
16+
17+
add_subdirectory(include)
18+
add_subdirectory(src)
19+
add_subdirectory(examples)
20+
21+
#### binsparse reference implementation configuration
22+
23+
FetchContent_Declare(
24+
binsparse
25+
GIT_REPOSITORY https://github.com/junikimm717/binsparse-reference-c
26+
GIT_TAG main
27+
)
28+
FetchContent_MakeAvailable(binsparse)
29+
target_include_directories(bsp-to-taco PUBLIC ${binsparse_SOURCE_DIR}/include)
30+
31+
#### taco configuration
32+
33+
option(CUDA "Build for NVIDIA GPU (CUDA must be preinstalled)" OFF)
34+
option(PYTHON "Build TACO for python environment" OFF)
35+
option(OPENMP "Build with OpenMP execution support" OFF)
36+
option(COVERAGE "Build with code coverage analysis" OFF)
37+
set(TACO_FEATURE_CUDA 0)
38+
set(TACO_FEATURE_OPENMP 0)
39+
set(TACO_FEATURE_PYTHON 0)
40+
if(CUDA)
41+
message("-- Searching for CUDA Installation")
42+
find_package(CUDA REQUIRED)
43+
add_definitions(-DCUDA_BUILT)
44+
set(TACO_FEATURE_CUDA 1)
45+
endif(CUDA)
46+
if(OPENMP)
47+
message("-- Will use OpenMP for parallel execution")
48+
add_definitions(-DUSE_OPENMP)
49+
set(TACO_FEATURE_OPENMP 1)
50+
endif(OPENMP)
51+
if(PYTHON)
52+
message("-- Will build Python extension")
53+
add_definitions(-DPYTHON)
54+
set(TACO_FEATURE_PYTHON 1)
55+
endif(PYTHON)
56+
57+
FetchContent_Declare(
58+
taco
59+
GIT_REPOSITORY https://github.com/junikimm717/taco
60+
GIT_TAG master
61+
)
62+
FetchContent_MakeAvailable(taco)
63+
configure_file(${taco_SOURCE_DIR}/include/taco/version.h.in ${taco_SOURCE_DIR}/include/taco/version.h @ONLY)
64+
target_include_directories(${PROJECT_NAME} PUBLIC ${taco_SOURCE_DIR}/include)
65+
66+
#### Project Configuration
67+
68+
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_BINARY_DIR}/include)
69+
target_link_libraries(${PROJECT_NAME} PUBLIC binsparse-rc taco)

compile_flags.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-I./include
2+
-I./build/include
3+
-DBSP_USE_HDF5
4+
-I/usr/include/hdf5/serial
5+
-I./build/_deps/taco-src/include
6+
-I./build/_deps/binsparse-src/include

examples/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-FileCopyrightText: 2024 Binsparse Developers
2+
#
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
5+
function(add_example example_name)
6+
add_executable(${example_name} ${example_name}.cpp)
7+
target_link_libraries(${example_name} bsp-to-taco)
8+
endfunction()
9+
10+
add_example(taco_experiments)
11+
add_example(parse_taco)

examples/parse_taco.cpp

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <binsparse/tensor.h>
2+
#include <binsparse/read_tensor.h>
3+
#include <binsparse/write_tensor.h>
4+
#include <iostream>
5+
#include "bsp_to_taco.hpp"
6+
using namespace std;
7+
8+
int main(int argc, char** argv) {
9+
if (argc < 2) {
10+
fprintf(stderr, "usage: ./parse_taco [file_name.h5]\n");
11+
return 1;
12+
}
13+
auto bsp = bsp_read_tensor(argv[1], NULL);
14+
taco::Tensor<double> tensor = makeTacoTensor(bsp);
15+
16+
// so it seems like taco.pack screws over the storage?
17+
// tensor.pack();
18+
19+
auto index = tensor.getStorage().getIndex();
20+
cout << "dimension:" << tensor.getDimensions().size() << "\n";
21+
for (int i = 0; i < index.numModeIndices(); i++) {
22+
cout << "mode index " << i
23+
<< ", indexArrays: " << index.getModeIndex(i).numIndexArrays()
24+
<< "\n====\n";
25+
for (int j = 0; j < index.getModeIndex(i).numIndexArrays(); j++) {
26+
auto array = index.getModeIndex(i).getIndexArray(j);
27+
for (int k = 0; k < array.getSize(); k++) {
28+
cout << array.get(k).get().int64Value << " ";
29+
}
30+
cout << "\n";
31+
}
32+
cout << "====\n";
33+
}
34+
35+
cout << "===================\n";
36+
cout << "Extract some values: \n";
37+
for (int k = 0; k < 10; k++) {
38+
for (int i = 0; i < 10; i++) {
39+
cout << tensor(k, i) << " ";
40+
}
41+
cout << "\n\n";
42+
}
43+
cout << "===================\n";
44+
45+
auto dims = tensor.getDimensions();
46+
cout << "dims:\n";
47+
for (auto &x : dims) std::cout << x << " ";
48+
cout << "\nvalues:\n";
49+
auto vals = tensor.getStorage().getValues();
50+
for (int i = 0; i < vals.getSize(); i++) std::cout << vals.get(i).get().float64Value << " ";
51+
cout << "\n";
52+
auto format = tensor.getStorage().getFormat();
53+
//bsp_destroy_tensor_t(bsp);
54+
return 0;
55+
}

examples/taco_experiments.cpp

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include <iostream>
2+
#include <taco.h>
3+
4+
using namespace taco;
5+
using namespace std;
6+
7+
int main() {
8+
int dim1 = 5, dim2 = 5;
9+
10+
// Define a 2D tensor in COO format
11+
12+
// Seems like this format was fucked up :sob:
13+
// Format coo({Compressed, Singleton});
14+
15+
/*
16+
order is 2, isUnique is false, isOrdered is true, isAOS is false.
17+
It seems like modeOrdering basically determines the order.
18+
19+
Ok, so for COO, you effectively need to figure out how to load
20+
layers in this kind of format, as seen below:
21+
*/
22+
23+
// Format fmt({Dense({ModeFormat::ORDERED, ModeFormat::UNIQUE}),
24+
// Compressed({ModeFormat::ORDERED, ModeFormat::UNIQUE})});
25+
// Format fmt = COO(2, false, true, false);
26+
27+
Format fmt({Compressed({ModeFormat::ORDERED, ModeFormat::NOT_UNIQUE}),
28+
Singleton({ModeFormat::ORDERED, ModeFormat::NOT_UNIQUE})});
29+
Tensor<double> A({5, 5}, fmt);
30+
31+
// TODO: generate with finch, use experimental parse_taco.cpp and check the
32+
// tensor below is the same.
33+
34+
// Insert non-zero values with explicit coordinates
35+
A.insert({0, 0}, 3.5);
36+
A.insert({1, 2}, 4.2);
37+
A.insert({1, 1}, 1.1);
38+
A.insert({2, 3}, 1.4);
39+
40+
A.pack();
41+
42+
auto index = A.getStorage().getIndex();
43+
44+
cout << "elements " << A.getAllocSize() << "\n";
45+
46+
cout << "dimension:" << A.getDimensions().size() << "\n";
47+
for (int i = 0; i < index.numModeIndices(); i++) {
48+
cout << "mode index " << i
49+
<< ", indexArrays: " << index.getModeIndex(i).numIndexArrays()
50+
<< "\n====\n";
51+
for (int j = 0; j < index.getModeIndex(i).numIndexArrays(); j++) {
52+
auto array = index.getModeIndex(i).getIndexArray(j);
53+
for (int k = 0; k < array.getSize(); k++) {
54+
cout << array.get(k).get().int32Value << " ";
55+
}
56+
cout << "\n";
57+
}
58+
cout << "====\n";
59+
}
60+
61+
cout << "===================\n";
62+
cout << "Extract some values: \n";
63+
for (int k = 0; k < 5; k++) {
64+
for (int i = 0; i < 5; i++) {
65+
cout << A(k, i) << " ";
66+
}
67+
cout << "\n\n";
68+
}
69+
cout << "===================\n";
70+
71+
cout << "elements:\n";
72+
auto elements = A.getStorage().getValues();
73+
for (int i = 0; i < elements.getSize(); i++) {
74+
cout << elements.get(i).get().float64Value << " ";
75+
}
76+
cout << "\n";
77+
cout << "data: \n";
78+
auto data = (double*) elements.getData();
79+
for (int i = 0; i < elements.getSize(); i++) {
80+
cout << data[i] << " ";
81+
}
82+
cout << "\n";
83+
cout << endl;
84+
return 0;
85+
}

include/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: 2024 Binsparse Developers
2+
#
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
5+
target_include_directories(bsp-to-taco PUBLIC .)

include/bsp_to_taco.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <binsparse/tensor.h>
2+
#include <binsparse/read_tensor.h>
3+
#include <taco.h>
4+
5+
taco::TensorBase makeTacoTensor(bsp_tensor_t& tensor);
6+
7+
taco::TensorBase readBinSparse(std::string filename);

src/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-FileCopyrightText: 2024 Binsparse Developers
2+
#
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
5+
target_sources(bsp-to-taco PRIVATE
6+
src/bsp_to_taco.cpp
7+
)

0 commit comments

Comments
 (0)