Skip to content
Draft
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
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${GraphMLIR_BINARY_DIR})

set(GraphMLIR_EXAMPLES OFF CACHE BOOL "Build examples")

#-------------------------------------------------------------------------------
# GoogleTest
#-------------------------------------------------------------------------------
set(BUILD_TESTS ON CACHE BOOL "Build tests")
if (BUILD_TESTS)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endif()

# if (BUILD_TESTS)
# enable_testing()
# add_subdirectory(tests)
# endif()

# Add MLIR and LLVM headers to the include path
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${MLIR_INCLUDE_DIRS})
Expand All @@ -80,6 +100,7 @@ include_directories(${GraphMLIR_SOURCE_DIR}/lib)
add_subdirectory(include)
add_subdirectory(lib)
add_subdirectory(tools)
add_subdirectory(unittests)

if(GraphMLIR_EXAMPLES)
add_subdirectory(examples)
Expand Down
2 changes: 0 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ BFS
PROPERTIES
LINKER_LANGUAGE C)



add_executable(bfsExample bfsExample.cpp)
add_dependencies(bfsExample graph-opt)
target_link_libraries(bfsExample BFS)
19 changes: 12 additions & 7 deletions examples/bfsExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,24 @@ int main() {

// use for weighted graph
Graph<float, 2> sample_graph(
graph::detail::GRAPH_ADJ_MATRIX_DIRECTED_WEIGHTED, 5);
sample_graph.addEdge(0, 2, 1);
sample_graph.addEdge(2, 3, 3);
sample_graph.addEdge(3, 2, 3);
sample_graph.addEdge(2, 2, 6);
sample_graph.addEdge(1, 2, 2);
graph::detail::GRAPH_INC_MATRIX_DIRECTED_WEIGHTED, 6);
sample_graph.addEdge(1,0,2);
sample_graph.addEdge(3,1,3);
sample_graph.addEdge(4,1,4);
sample_graph.addEdge(4,2,5);
sample_graph.addEdge(5,1,6);

// this will print the original graph.
std::cout << "Printing graph in format it was entered ( "
"GRAPH_ADJ_MARIX_DIRECTED_WEIGHTED )\n";
sample_graph.printGraphOg();

auto x = sample_graph.get_Memref();
auto x1 = sample_graph.get_Memref();

if (x == x1) {
std::cout<< "the two memref are equal "<<std::endl;
}

// this will print the linear 2d matrix in 2d form.

Expand Down
6 changes: 4 additions & 2 deletions include/Interface/Container.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
// - The storage order is NCHW.
template <typename T, size_t N> class MemRef {
public:
// Default constructor.
MemRef(){};
// Constructor from shape.
MemRef(intptr_t sizes[N], T init = T(0));
// Constructor from data.
Expand Down Expand Up @@ -62,10 +64,10 @@ template <typename T, size_t N> class MemRef {
T &operator[](size_t index);
// release the pointer
T *release();
//comparision operator
bool operator==(const MemRef<T, N> &other);

protected:
// Default constructor.
MemRef(){};
// Set the strides.
// Computes the strides of the transposed tensor for transpose=true.
void setStrides();
Expand Down
1 change: 1 addition & 0 deletions lib/Interface/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_library(Container Container.cpp)
add_library(GraphContainer GraphContainer.cpp)
34 changes: 34 additions & 0 deletions lib/Interface/Container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstdio>
#include <memory>
#include <numeric>
#include <stdexcept>
Expand Down Expand Up @@ -277,4 +279,36 @@ template <typename T, size_t N> T *MemRef<T, N>::release() {
return temp;
}

template <typename T, size_t N>
bool MemRef<T, N>::operator==(const MemRef<T, N> &other) {
intptr_t x1 = this->sizes[0];
intptr_t y1 = this->sizes[1];
intptr_t x2 = other.sizes[0];
intptr_t y2 = other.sizes[1];

// compare the sizes array and size
if (x1 != x2 || y1 != y2 || this->size != other.size) {
return false;
}

// compare the strides
if (this->strides[0] != this->strides[0] ||
other.strides[1] != other.strides[1]) {
return false;
}

for (intptr_t i = 0; i < x1; i++) {
for (intptr_t j = 0; j < y1; j++) {
if (this->allocated[i * x1 + y1] != other.allocated[i * x1 + y1]) {
return false;
}
// if(this->aligned[i * x1 + y1] != other.aligned[i * x1 + y1]) {
// return false;
// }
}
}

return true;
}

#endif // CORE_CONTAINER_DEF
6 changes: 3 additions & 3 deletions lib/Interface/GraphContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void Graph<T, N>::addEdge(T Node1, T Node2, T EdgeWeight) {
this->incMat[Node2][edgeCount] = EdgeWeight;
break;
case graph::detail::GRAPH_INC_MATRIX_DIRECTED_WEIGHTED:
EdgeWeight = std::abs(sqrt(EdgeWeight));
EdgeWeight = EdgeWeight;
this->incMat[Node1][edgeCount] = EdgeWeight;
this->incMat[Node2][edgeCount] = -EdgeWeight;
this->edgeCount += 1;
Expand Down Expand Up @@ -461,9 +461,9 @@ template <typename T, size_t N> void Graph<T, N>::graph_to_MemRef_descriptor() {
for (k = flag + 1; k < this->incMat.size() && flag != -2; k++) {
if ((this->incMat[k][j] != 0) && flag != -1) {
if (this->incMat[k][j] < this->incMat[int(flag)][j])
linear[int(flag) * x + k] = pow(incMat[k][j], 2);
linear[int(flag) * x + k] = incMat[k][j];
else
linear[k * x + int(flag)] = pow(incMat[k][j], 2);
linear[k * x + int(flag)] = incMat[k][j];
flag = -1;
}
}
Expand Down
2 changes: 2 additions & 0 deletions unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(Interface)

12 changes: 12 additions & 0 deletions unittests/Interface/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
add_executable(
InterfaceTests
GraphContainerTest.cpp
ContainerTest.cpp
)

target_link_libraries(InterfaceTests gtest gtest_main pthread BFS)

add_dependencies(InterfaceTests Container GraphContainer)

include(GoogleTest)
gtest_discover_tests(InterfaceTests)
1 change: 1 addition & 0 deletions unittests/Interface/ContainerTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <gtest/gtest.h>
Loading