Skip to content

Commit

Permalink
Final Implementation llvm16
Browse files Browse the repository at this point in the history
  • Loading branch information
nishant-sachdeva committed Dec 21, 2023
1 parent ea10020 commit 6db1f7b
Show file tree
Hide file tree
Showing 271 changed files with 20,708 additions and 120,716 deletions.
63 changes: 27 additions & 36 deletions Manylinux2014_Compliant_Source/pkg/IR2Vec/refactoredCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,50 +355,41 @@ ir2vecHandlerObject *createIR2VECObject(const char *filename, const char *output

PyObject *initEmbedding(PyObject *self, PyObject *args) {
Py_Initialize();
PyObject *Embedding_dict = PyDict_New();
// setting default values
PyDict_SetDefault(Embedding_dict, PyUnicode_FromString("fileName"), Py_None);
PyDict_SetDefault(Embedding_dict, PyUnicode_FromString("outputFile"), Py_None);
PyDict_SetDefault(Embedding_dict, PyUnicode_FromString("Message"), PyUnicode_FromString(""));
PyDict_SetDefault(Embedding_dict, PyUnicode_FromString("Status"), Py_False);

const char *filename = "\0";
const char *mode = "\0";
const char *level = "\0";
const char *output_file = "\0";

if (PyArg_ParseTuple(args, "s", &filename, &output_file)) {
if (fileNotValid(filename)) {
PyDict_SetItemString(
Embedding_dict, "Message",
PyUnicode_FromString(
"Eroneous or empty .bc/.ll file location entred"));
PyDict_SetItemString(Embedding_dict, "Status", Py_False);
return Embedding_dict;
}
if (!PyArg_ParseTuple(args, "sss|s", &filename, &mode, &level, &output_file)) {
// raise error here
PyErr_SetString(PyExc_TypeError, "Invalid Arguments");
return NULL;
}

if (string(output_file).empty() == false) {
if (fileNotValid(output_file)) {
PyDict_SetItemString(
Embedding_dict, "Message",
PyUnicode_FromString(
"Eroneous or empty output file location entred"));
PyDict_SetItemString(Embedding_dict, "Status", Py_False);
return Embedding_dict;
}
if (fileNotValid(filename)) {
PyErr_SetString(PyExc_TypeError, "Invalid File Path");
return NULL;
}

if (string(output_file).empty() == false) {
if (fileNotValid(output_file)) {
PyErr_SetString(PyExc_TypeError, "Invalid Output File Path");
return NULL;
}
}

PyDict_SetItemString(Embedding_dict, "fileName", PyUnicode_FromString(filename));
PyDict_SetItemString(Embedding_dict, "outputFile", PyUnicode_FromString(output_file));
PyDict_SetItemString(Embedding_dict, "Message", PyUnicode_FromString("Success"));
PyDict_SetItemString(Embedding_dict, "Status", Py_True);
return Embedding_dict;
} else {
PyDict_SetItemString(Embedding_dict, "Status", Py_False);
PyDict_SetItemString(Embedding_dict, "Message",
PyUnicode_FromString("Invalid Arguments"));
return Embedding_dict;
if (string(mode) != string("sym") && string(mode) != string("fa")) {
PyErr_SetString(PyExc_TypeError,
"Eroneous mode entered . Either of sym, fa should be "
"specified");
return NULL;
}
}

if (level[0] != 'p' && level[0] != 'f') {
PyErr_SetString(PyExc_TypeError,
"Invalid level specified: Use either p or f");
return NULL;
}

ir2vecHandlerObject *ir2vecObj = createIR2VECObject(filename, output_file, mode, level);

Expand Down
2 changes: 1 addition & 1 deletion Manylinux2014_Compliant_Source/pkg/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ cmake -DCMAKE_BUILD_TYPE=Release ../src && make -j"$(nproc)" && make install
cd ..
cp src/include/*.h Manylinux2014_Compliant_Source/pkg/IR2Vec/
cp build/version.h Manylinux2014_Compliant_Source/pkg/IR2Vec/
cp vocabulary/seedEmbeddingVocab-*.txt Manylinux2014_Compliant_Source/pkg/IR2Vec/
cp vocabulary/seedEmbeddingVocab-llvm16.txt Manylinux2014_Compliant_Source/pkg/IR2Vec/

bash Manylinux2014_Compliant_Source/pkg/regen-oracle.sh
10 changes: 4 additions & 6 deletions Manylinux2014_Compliant_Source/pkg/tests/test_ir2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ def test_fa_p():
progVector2 = initObj.getProgramVector()
assert_valid_progVector(progVector2)

for idx, v in enumerate(progVector1):
assert v == pytest.approx(progVector2[idx], abs=ABS_ACCURACY)
assert(progVector1 == pytest.approx(progVector2, abs=ABS_ACCURACY))

p_vectors.append(progVector1)

Expand All @@ -138,13 +137,12 @@ def test_sym_p():
assert(initObj is not None)

progVector1 = IR2Vec.getProgramVector(initObj)
assert(progVector1 is not None)
assert_valid_progVector(progVector1)

progVector2 = initObj.getProgramVector()
assert(progVector2 is not None)
assert_valid_progVector(progVector2)

for idx, v in enumerate(progVector1):
assert v == pytest.approx(progVector2[idx], abs=ABS_ACCURACY)
assert progVector1 == pytest.approx(progVector2, abs=ABS_ACCURACY)

p_vectors.append(progVector1)

Expand Down
58 changes: 56 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Please see [here](https://compilers.cse.iith.ac.in/projects/ir2vec/) for more de
- [On-demand Flow-Aware Embeddings](#on-demand-flow-aware-embeddings)
- [On-demand Symbolic Embeddings](#on-demand-symbolic-embeddings)
- [Using Libraries](#using-libraries)
- [Using Python package (IR2Vec-Wheels)](#using-python-package-ir2vec-wheels)
- [Binaries, Libraries and Wheels - Artifacts](#binaries-libraries-and-wheels---artifacts)
- [Experiments](#experiments)
- [Note](#note)
- [Citation](#citation)
Expand Down Expand Up @@ -188,6 +190,58 @@ for (auto val : pgmVec)
outs() << val << "\t";
```
## Using Python package (IR2Vec-Wheels)
- Input:
- .ll/.bc file for which embeddings are needed
- `fa` -> Flow-Aware Encoddings; `sym` -> Symbolic Encodings
- `p` -> program level; `f` -> function level
- Output:
- A dictionary containing:
- `Instruction_Dict`: Key: Instruction[String]; Value : Embedding Vector
- `Function_Dict`: Key: Function name[String]; Value : Embedding Vector
- `Program_List`: Program/Module Name[String]; Embedding Vector
- `Message`: [String] Appropriate debug message.
- `Status`: [Bool] True if everything went fine else False
- The following code snippet contains an example to demonstrate the usage of the package.
```python
import IR2Vec
initObj = IR2Vec.initEmbedding(full_path, "fa", "p")
progVector1 = IR2Vec.getProgramVector(initObj)
functionVectorMap1 = IR2Vec.getFunctionVectors(initObj)
instructionVectorsMap1 = IR2Vec.getInstructionVectors(initObj)
progVector2 = initObj.getProgramVector()
functionVectorMap2 = initObj.getFunctionVectors()
instructionVectorMap2 = initObj.getInstructionVectors()
for fun, funcObj in functionVectorMap.items():
assert fun == funcObj["demangledName"]
functionOutput1 = IR2Vec.getFunctionVectors(
initObj,
funcObj["actualName"],
)
functionOutput2 = initObj.getFunctionVectors(
funcObj["actualName"]
)
assert(
functionOutput1[fun]["vector"] == pytest.approx(
functionOutput2[fun]["vector"], abs=ABS_ACCURACY
)
)
assert(
funcObj["vector"] == pytest.approx(functionOutput1[fun]["vector"], abs=ABS_ACCURACY)
)
```
## Binaries, Libraries and Wheels - Artifacts
Binaries, Libraries (.a and .so), and whl files are autogenerated for every relevant check-in using GitHub Actions. Such generated artifacts are tagged along with the successful runs of [`Publish`](https://github.com/IITH-Compilers/IR2Vec/actions?query=workflow%3APublish) and [`Build Wheels`](https://github.com/IITH-Compilers/IR2Vec/actions/workflows/wheel.yml) actions.

## Experiments

### Note
Expand Down Expand Up @@ -220,7 +274,7 @@ keywords = {heterogeneous systems, representation learning, compiler optimizatio
}
```
## Contributions
Please feel free to raise issues to file a bug, to pose a question, or to initiate any related discussions. Pull requests are welcome :)
Please feel free to raise issues to file a bug, pose a question, or initiate any related discussions. Pull requests are welcome :)

## License
IR2Vec is released under a BSD 4-Clause License. See the LICENSE file for more details.
IR2Vec is released under a BSD 4-Clause License. See the LICENSE file for more details.
14 changes: 6 additions & 8 deletions seed_embeddings/OpenKE/generate_embedding_ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,12 @@ def findRep(src, dest, index_dir):
"epoch": arg_conf.epoch,
"dim": arg_conf.dim,
"index_dir": arg_conf.index_dir,
"nbatches": tune.grid_search([2**x for x in range(7, 11)]),
# [300, 350]),
#
# ),
"margin": tune.grid_search([x for x in np.arange(3, 5, 0.05)]),
# tune.grid_search([3.5])
# [x for x in np.arange(3.0, 5.0, 1)]
# ),
"nbatches": tune.grid_search([
x for x in range(300, 500, 50)
]),
"margin": tune.grid_search([
x for x in np.arange(3, 5, 0.5)
]),
}

try:
Expand Down
Loading

0 comments on commit 6db1f7b

Please sign in to comment.