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

Frontend #13

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
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
61 changes: 51 additions & 10 deletions examples/bfsExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,62 @@

#include <Interface/graph.h>
#include <Interface/memref.h>
#include </home/andros/GraphMLIR/include/Interface/Container.h>
#include </home/andros/GraphMLIR/include/Interface/GraphContainer.h>
#include <iostream>

int main() {
std::cout << "Reached here !!!\n";
// std::cout << "Reached here !!!\n";

// float sample_graph1_array[9] = {1, 1, 1, 1, -8, 1, 1, 1, 1};
// intptr_t sample_graph_length = 3;
// intptr_t sample_graph_width = 3;
// float *allocation_pointer = (float *)malloc(sizeof(float));
// intptr_t sample_graph_sizes[2] = {sample_graph_width, sample_graph_length};
// intptr_t sample_graph_strides[2] = {sample_graph_width, sample_graph_length};

// MemRef_descriptor sample_graph =
// MemRef_Descriptor(allocation_pointer, sample_graph1_array, 0,
// sample_graph_sizes, sample_graph_strides);

// graph::graph_bfs(sample_graph, sample_graph, sample_graph);

int n, m;
float adjMatrix[1000][1000] = {0};

std::cout << "Enter the number of nodes and edges: \n";
std::cin >> n >> m;

std::cout << "Enter the edges of the graph.\n";
for (int i = 0; i < m; ++i) {
int x, y;
std::cin >> x >> y;
adjMatrix[x][y] = 1;
adjMatrix[y][x] = 1;
}

int inputSize = n * n;
float *inputGraph = (float *)malloc(inputSize * sizeof(float));

for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
inputGraph[n * i + j] = (float)adjMatrix[i][j];
}
}

intptr_t nodes = n;

float sample_graph1_array[9] = {1, 1, 1, 1, -8, 1, 1, 1, 1};
intptr_t sample_graph_length = 3;
intptr_t sample_graph_width = 3;
float *allocation_pointer = (float *)malloc(sizeof(float));
intptr_t sample_graph_sizes[2] = {sample_graph_width, sample_graph_length};
intptr_t sample_graph_strides[2] = {sample_graph_width, sample_graph_length};

MemRef_descriptor sample_graph =
MemRef_Descriptor(allocation_pointer, sample_graph1_array, 0,
sample_graph_sizes, sample_graph_strides);
intptr_t graph_sizes[2] = {nodes, nodes};
intptr_t graph_strides[2] = {nodes, nodes};

Graph<float, 1> adjMatrix_graph(nodes, &inputGraph);

MemRef_descriptor input_graph = MemRef_Descriptor(
allocation_pointer, inputGraph, 0, graph_sizes, graph_strides);

graph::graph_bfs(input_graph, input_graph, input_graph);

graph::graph_bfs(sample_graph, sample_graph, sample_graph);
std::cout << "Graph using adjacency matrix created! \n";
}
3 changes: 2 additions & 1 deletion include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(Dialect)
add_subdirectory(Dialect)
add_subdirectory(Interface)
3 changes: 3 additions & 0 deletions include/Interface/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_library(Interface Container.h GraphContainer.h)

set_target_properties(Interface PROPERTIES LINKER_LANGUAGE C)
54 changes: 54 additions & 0 deletions include/Interface/Container.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//===- Container.h --------------------------------------------------------===//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//
//
// Container descriptor.
//
//===----------------------------------------------------------------------===//


#ifndef INTERFACE_GRAPH_CORE_CONTAINER_H
#define INTERFACE_GRAPH_CORE_CONTAINER_H

#include <memory>
#include <stdint.h>
#include <vector>

// MemRef descriptor.
// - T represents the type of the elements.
// - N represents the number of dimensions.
template <typename T, size_t N> class MemRef {

protected:
// Default constructor.
MemRef() {};

// Data.
// The `aligned` and `allocated` members point to the same address, `aligned`
// member is responsible for handling data, and `allocated` member is
// resposible for handling the memory space.
T *allocated;
T *aligned;
// Offset.
intptr_t offset = 0;
// Shape.
intptr_t sizes[N];
// Strides.
intptr_t strides[N];
// Number of elements.
size_t size;
};

#endif // INTERFACE_GRAPH_CORE_CONTAINER.
42 changes: 42 additions & 0 deletions include/Interface/GraphContainer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//===- GraphContainer.h ---------------------------------------------------===//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//
//
// Graph container descriptor.
//
//===----------------------------------------------------------------------===//

#ifndef INTERFACE_GRAPHCONTAINER_H
#define INTERFACE_GRAPHCONTAINER_H

#include </home/andros/GraphMLIR/include/Interface/Container.h>

// Graph container.
// - T represents the type of the elements.
// - N represents the number of dimensions.
template <typename T, size_t N> class Graph : public MemRef<T, N> {
// V is the number of vertices/nodes.
T V;

public:
// For Adjaceny Matrix.
Graph(T V, T** adjMatrix);
// TODO:
// Add Different contructors.
};

#include </home/andros/GraphMLIR/lib/Interface/GraphContainer.cpp>

#endif // INTERFACE_GRAPHCONTAINER_H
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(Conversion)
add_subdirectory(Dialect)
add_subdirectory(Interface)
1 change: 1 addition & 0 deletions lib/Interface/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_library(GraphInterface GraphContainer.cpp)
50 changes: 50 additions & 0 deletions lib/Interface/GraphContainer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//===- GraphContainer.cpp -------------------------------------------------===//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//
//
// This file implements the Graph container descriptor.
//
//===----------------------------------------------------------------------===//

#ifndef GRAPH_CONTAINER_DEF
#define GRAPH_CONTAINER_DEF

#include </home/andros/GraphMLIR/include/Interface/Container.h>
#include </home/andros/GraphMLIR/include/Interface/GraphContainer.h>

// Adjaceny Matrix constructor.
template <typename T, size_t N> Graph<T, N>::Graph(T V, T **adjMatrix) : MemRef<T, N>() {
this->size[0] = V;
this->size[1] = V;
this->strides[0] = V;
this->strides[1] = V;
this->allocated = new T[this->size];
//TODO
// Add the implementation for passing data to alignned.
this->aligned = this->allocated;
int k = 0;
for (int i = 0; i < size[0]; i++) {
for (int j = 0; j < size[1]; j++) {
this->aligned[k] = (T)adjMatrix[i][j];
k++;
}
}
};


// TODO
// Implement the contructor for different implementation.

#endif // GRAPH_CONTAINER_DEF