Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
build
_dump*
.vscode
temp*
26 changes: 13 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
cmake_minimum_required(VERSION 3.14)
project(Vectron)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wno-return-type-c-linkage")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -fvisibility-inlines-hidden -Wno-return-type-c-linkage -Wno-gnu-zero-variadic-macro-arguments -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS_DEBUG "-g -fno-limit-debug-info")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
include_directories(.)

set(CPM_DOWNLOAD_VERSION 0.32.3)
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))

if(NOT(EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake...")
file(DOWNLOAD https://github.com/TheLartians/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake ${CPM_DOWNLOAD_LOCATION})
endif()

include(${CPM_DOWNLOAD_LOCATION})

CPMAddPackage(
Expand All @@ -22,7 +24,8 @@ CPMAddPackage(
GIT_TAG e7da44d5151e21f153925781ad29334ae0786101
EXCLUDE_FROM_ALL YES
OPTIONS "BUILD_SHARED_LIBS OFF"
"CMAKE_POSITION_INDEPENDENT_CODE ON")
"CMAKE_POSITION_INDEPENDENT_CODE ON")

if(xz_ADDED)
set_target_properties(xz PROPERTIES EXCLUDE_FROM_ALL ON)
set_target_properties(xzdec PROPERTIES EXCLUDE_FROM_ALL ON)
Expand All @@ -40,27 +43,24 @@ set(VECTRON_FILES
ir/env_select.cpp
ir/env_select.h
ir/vectron.cpp
ir/loop.cpp
ir/loop.h
ir/vectron.h)
add_library(vectron SHARED ${VECTRON_FILES})

# Include directories for your custom LLVM
target_include_directories(vectron PRIVATE
"${CODON_PATH}/include"
"${LLVM_PATH}/include")
target_include_directories(vectron PRIVATE "${CODON_PATH}/include")

# Link directories and libraries for your custom LLVM
target_link_directories(vectron PRIVATE
"${CODON_PATH}/lib/codon"
"${LLVM_PATH}/lib")
target_link_directories(vectron PRIVATE "${CODON_PATH}/lib/codon")

target_link_libraries(vectron PRIVATE codonrt codonc LLVMCore LLVMSupport LLVMTarget)
target_link_libraries(vectron PRIVATE codonrt codonc) # LLVMCore LLVMSupport LLVMTarget

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CODON_PATH}/lib/codon" CACHE PATH "Use the existing Codon installation" FORCE)
set(CMAKE_INSTALL_PREFIX "${CODON_PATH}/lib/codon" CACHE PATH "Use the existing Codon installation" FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

install(TARGETS vectron DESTINATION plugins/vectron/build)
install(FILES plugin.toml DESTINATION plugins/vectron)
install(FILES stdlib/experimental/simd.codon DESTINATION stdlib/experimental)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/stdlib DESTINATION plugins/vectron)

40 changes: 40 additions & 0 deletions applications/v1.0/hamming_distance.codon
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import time
import sys
from vectron.dispatcher import *

var_type = "i16"

@vectron_kernel
def hamming(t, q):
M = [[0 for i in range(len(q) + 1)] for j in range(len(t) + 1)]
for i in range(1, len(q) + 1):
for j in range(1, len(t) + 1):
if j - i <= -1 or j - i >= 1:
if j - i == -1 or j - i == 1:
M[i][j] = -10000
else:
M[i][j] = max(
M[i - 1][j - 1] + (0 if q[i - 1] == t[j - 1] else 1),
0, 0
)
return M[-1][-1]

@vectron_scheduler
def invoke(x, y):
score = [[0 for _ in range(len(y))] for __ in range(len(x))]
for i in range(len(x)):
for j in range(len(y)):
score[i][j] = hamming(x[i], y[j])
return score

with open(sys.argv[-1], 'r') as file:
seqs_x = [line.strip() for line in file]

with open(sys.argv[-2], 'r') as file:
seqs_y = [line.strip() for line in file]

SEQ_NO_T = len(seqs_x)
SEQ_NO_Q = len(seqs_y)

with time.timing("Total: "):
d = invoke(seqs_x, seqs_y)
35 changes: 35 additions & 0 deletions applications/v1.0/lcs.codon
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import time
import sys
from vectron.dispatcher import *

var_type = "i16"

@vectron_kernel
def lcs(t, q):
M = [[0 for __ in range(len(q) + 1)] for _ in range(len(t) + 1)]
for i in range(1, len(q) + 1):
for j in range(1, len(t) + 1):
M[i][j] = max(M[i - 1][j - 1] + (1 if q[i - 1] == t[j - 1] else 0),
M[i - 1][j],
M[i][j - 1])
return M[-1][-1]

@vectron_scheduler
def invoke(x, y):
score = [[0 for _ in range(len(y))] for __ in range(len(x))]
for i in range(len(x)):
for j in range(len(y)):
score[i][j] = lcs(x[i], y[j])
return score

with open(sys.argv[-1], 'r') as file:
seqs_x = [line.strip() for line in file]

with open(sys.argv[-2], 'r') as file:
seqs_y = [line.strip() for line in file]

SEQ_NO_T = len(seqs_x)
SEQ_NO_Q = len(seqs_y)

with time.timing("Total: "):
d = invoke(seqs_x, seqs_y)
47 changes: 47 additions & 0 deletions applications/v1.0/levenshtein_distance.codon
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import time
import sys
from vectron.dispatcher import *

var_type = "i16"

# Use vectron to annotate DP kernel
@vectron_kernel
def levenshtein(Q, T):
M = [[0] * (len(Q) + 1) for _ in range(len(T) + 1)]
for i in range(len(T) + 1):
M[i][0] = -2 + i * -4
for j in range(len(Q) + 1):
M[0][j] = -2 + j * -4

# Kernel
for i in range(1, len(T)+1):
for j in range(1, len(Q)+1):
M[i][j] = max(
M[i - 1][j] - 2,
M[i][j - 1] - 2,
M[i-1][j-1] + (2 if Q[j-1] == T[i-1] else -3)
)

# Aggregation
return M[-1][-1]

# Use vectron_scheduler to annotate function that invokes the kernel on list of pairs
@vectron_scheduler
def invoke(x, y):
score = [[0 for i in range(len(y))] for j in range(len(x))]
for i in range(len(x)):
for j in range(len(y)):
score[i][j] = levenshtein(x[i], y[j])
return score

with open(sys.argv[-1], 'r') as file:
seqs_x = [line.strip() for line in file]

with open(sys.argv[-2], 'r') as file:
seqs_y = [line.strip() for line in file]

SEQ_NO_T = len(seqs_x)
SEQ_NO_Q = len(seqs_y)

with time.timing("Total: "):
d = invoke(seqs_x, seqs_y)
51 changes: 51 additions & 0 deletions applications/v1.0/manhattan_tourist.codon
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import time
import sys
from vectron.dispatcher import *

var_type = "i16"


@vectron_cmp
def S(x, a, b, am, y):
"""
Due to ambiguous elements ('N'), a specialized match function has been used
instead of a ternary operator, hence the "@vectron.cmp" decorator.
"""
if str(x) == "N" or str(y) == "N":
return am
elif x == y:
return a
else:
return b

@vectron_kernel
def manhattan(t, q):
M = [[0 for i in range(len(q) + 1)] for j in range(len(t) + 1)]
for i in range(1, len(q) + 1):
for j in range(1, len(t) + 1):
M[i][j] = max(
M[i][j - 1] + S(q[i - 1], 4, 1, 0, t[j - 1]),
0,
M[i - 1][j] + S(q[i - 1], 5, 3, 1, t[j - 1])
)
return M[-1][-1]

@vectron_scheduler
def invoke(x, y):
score = [[0 for _ in range(len(y))] for __ in range(len(x))]
for i in range(len(x)):
for j in range(len(y)):
score[i][j] = manhattan(x[i], y[j])
return score

with open(sys.argv[-1], 'r') as file:
seqs_x = [line.strip() for line in file]

with open(sys.argv[-2], 'r') as file:
seqs_y = [line.strip() for line in file]

SEQ_NO_T = len(seqs_x)
SEQ_NO_Q = len(seqs_y)

with time.timing("Total: "):
d = invoke(seqs_x, seqs_y)
52 changes: 52 additions & 0 deletions applications/v1.0/min_cost_path.codon
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import time
import sys
from vectron.dispatcher import *

var_type = "i16"


@vectron_cmp
def S(x, a, b, am, y):
"""
Due to ambiguous elements ('N'), a specialized match function has been used
instead of a ternary operator, hence the "@vectron.cmp" decorator.
"""
if str(x) == "N" or str(y) == "N":
return am
elif x == y:
return a
else:
return b

@vectron_kernel
def min_cost_path(h, m):
q = [[0 if (i == 0 and j == 0) else (1 + i * (2)) if (j == 0 and i > 0) else (1 + j * (3)) if (i == 0 and j > 0) else 0 for j in range(len(m) + 1)] for i in range(len(h) + 1)]
for i in range(1, len(m) + 1):
for j in range(1, len(h) + 1):
q[i][j] = max(
q[i - 1][j - 1] + S(m[i - 1], 2, -3, -1, h[j - 1]),
q[i - 1][j] + S(m[i - 1], 1, -2, -1, h[j - 1]),
q[i][j - 1] + S(m[i - 1], 1, -2, -2, h[j - 1])
)

return q[-1][-1]

@vectron_scheduler
def invoke(x, y):
score = [[0 for _ in range(len(y))] for __ in range(len(x))]
for i in range(len(x)):
for j in range(len(y)):
score[i][j] = min_cost_path(x[i], y[j])
return score

with open(sys.argv[-1], 'r') as file:
seqs_x = [line.strip() for line in file]

with open(sys.argv[-2], 'r') as file:
seqs_y = [line.strip() for line in file]

SEQ_NO_T = len(seqs_x)
SEQ_NO_Q = len(seqs_y)

with time.timing("Total: "):
d = invoke(seqs_x, seqs_y)
50 changes: 50 additions & 0 deletions applications/v1.0/needleman_wunsch.codon
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import time
import sys
from vectron.dispatcher import *

var_type = "i16"


@vectron_cmp
def M(x, a, b, am, y):
"""
Due to ambiguous elements ('N'), a specialized match function has been used
instead of a ternary operator, hence the "@vectron.cmp" decorator.
"""
if str(x) == "N" or str(y) == "N":
return am
elif x == y:
return a
else:
return b

@vectron_kernel
def nw(h, m):
q = [[0 if (i == 0 and j == 0) else (i * (-4)) if (j == 0 and i > 0) else (j * (-4)) if (i == 0 and j > 0) else 0 for j in range(len(m) + 1)] for i in range(len(h) + 1)]
for i in range(1, len(m) + 1):
for j in range(1, len(h) + 1):
q[i][j] = max(q[i - 1][j - 1] + M(m[i - 1], 2, -4, -3, h[j - 1]),
q[i - 1][j] - 4,
q[i][j - 1] - 4)

return q[-1][-1]

@vectron_scheduler
def invoke(x, y):
score = [[0 for _ in range(len(y))] for __ in range(len(x))]
for i in range(len(x)):
for j in range(len(y)):
score[i][j] = nw(x[i], y[j])
return score

with open(sys.argv[-1], 'r') as file:
seqs_x = [line.strip() for line in file]

with open(sys.argv[-2], 'r') as file:
seqs_y = [line.strip() for line in file]

SEQ_NO_T = len(seqs_x)
SEQ_NO_Q = len(seqs_y)

with time.timing("Total: "):
d = invoke(seqs_x, seqs_y)
Loading