Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8d8a94e
Oops. Some lingering changes
the-Bruce Apr 21, 2021
805be47
Merge branch 'master' into Dimension
the-Bruce Apr 21, 2021
5ca51e3
Fixed mistake with pointer comparisons
lloyd-conlin Apr 23, 2021
187d150
Merge branch 'codegen' into TypeChecking
lloyd-conlin Apr 23, 2021
b96b26f
Added more detail to funcdef dimension error message
the-Bruce Apr 23, 2021
4912ad3
Update for type error
lloyd-conlin Apr 23, 2021
b7a2d90
Merge branch 'Dimension' into TypeChecking
lloyd-conlin Apr 23, 2021
79b54e2
Oops. Idiotic bug
the-Bruce Apr 23, 2021
970b897
Oops. Even more idiotic bug
the-Bruce Apr 23, 2021
1dc4863
Merge branch 'TypeChecking' into Dimension
the-Bruce Apr 23, 2021
24714b9
Fix a bug in decomp dimensioning of 1d matrices
the-Bruce Apr 23, 2021
54f3b4b
Replacement of <span> with <string_view>
Nightingale-33 Apr 23, 2021
5b91033
Remove the compile warnings.
the-Bruce Apr 23, 2021
179e23f
Fix argument errors
the-Bruce Apr 23, 2021
a75b34e
Found another bug. Squashed. Handle * in function return types
the-Bruce Apr 23, 2021
c4b7996
Fix merge botch
the-Bruce Apr 23, 2021
2305f1c
Merge branch 'FixMergeMistake' into Dimension
the-Bruce Apr 23, 2021
e2656de
Stable codegen
AlfiePowers Apr 23, 2021
3a701a4
Change rank 0 stuff to use isLiteral.
the-Bruce Apr 23, 2021
071932c
Before merge
AlfiePowers Apr 23, 2021
8fd39ad
Merge remote-tracking branch 'origin/isLiteralChange' into codegen-wip
AlfiePowers Apr 23, 2021
44e84a0
Fix matrix sizing when no seperators are present
the-Bruce Apr 23, 2021
c175053
Merge branch 'isLiteralChange' into Dimension
the-Bruce Apr 23, 2021
bf1d9cd
Fix for function argument count in semantic pass & function overrides
AlfiePowers Apr 23, 2021
25a26e2
Fix rank not matching dimension
the-Bruce Apr 23, 2021
a65b0e8
Merge remote-tracking branch 'origin/Dimension' into codegen-wip
AlfiePowers Apr 23, 2021
5f5403c
Added computation mode compile options for GPU / CPU codegen only
AlfiePowers Apr 24, 2021
9bea61c
Precompiled CPU
AlfiePowers Apr 24, 2021
69b4ab0
More CPU binaries
AlfiePowers Apr 24, 2021
54e9627
Fix ternary not establishing type correctly
the-Bruce Apr 28, 2021
641474e
Fix function call issue
the-Bruce Apr 28, 2021
90cc0c8
Merge remote-tracking branch 'origin/codegen-wip' into Dimension
the-Bruce Apr 28, 2021
d244132
Fixed semantic pass for recursive functions
lloyd-conlin May 2, 2021
331a917
Merge branch 'Dimension' of github.com:the-Bruce/CUDA_Matters into Di…
lloyd-conlin May 2, 2021
2a10888
Fix minor problem
lloyd-conlin May 2, 2021
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
5 changes: 5 additions & 0 deletions cudaBLAS/compileBatch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os

for n in [300,400,500,750,1000]:
filename = str(n) + ".cm"
os.system("./compile.sh " + filename)
18 changes: 18 additions & 0 deletions cudaBLAS/curvefit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from scipy.optimize import curve_fit
import numpy as np

xdata = [70,80,90,100,110,120,130,140,150,160,
170,180,190,200,250,300,400,500,750,1000]

ydata = [0.163639,0.230039,0.286963,0.343532,0.486311,0.511364,0.460507,0.604441,0.7165,0.789863,0.900274,0.968071,0.970639,1.072578,1.356337,1.740857,1.988335,2.903016,3.637857,4.235182]


def sigmoid(x, L ,x0, k, b):
y = L / (1 + np.exp(-k*(x-x0)))+b
return (y)

p0 = [max(ydata), np.median(xdata),1,min(ydata)] # this is an mandatory initial guess

popt, pcov = curve_fit(sigmoid, xdata, ydata)

print(popt)
31 changes: 31 additions & 0 deletions cudaBLAS/generateLargeMatrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import numpy as np
import os

def printAsCuMatMatrix(mat):
np.set_printoptions(threshold=9999999999)
file = "["
file = file + np.array2string(mat, separator=', ').replace('],', '\\').replace('[', '').replace(']','')
file = file + ']'
return file


# for n in [300,400,500,750,1000]:
n = 10
dim = (n,n)

x = np.ones(dim) * 2.1
# y = np.identity(dim[0]) * 1

programHeader = "func float[" + str(n) + "," + str(n) + "] main { a = "
programHeader = programHeader + printAsCuMatMatrix(x).replace("\n", "")
programHeader = programHeader + "\n"
programHeader = programHeader + "return a * a"
programHeader = programHeader + "}"
text_file = open("pythonoutput.cm", "w")

text_file.write(programHeader)

text_file.close()

os.system("cp pythonoutput.cm ../cmake-build-debug/src/compiler/src/python.cm")
os.system("cp pythonoutput.cm ../cmake-build-debug/src/compiler/src/python.cm")
14 changes: 10 additions & 4 deletions cudaBLAS/generateLargeMult.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import os

def printAsCuMatMatrix(mat):
np.set_printoptions(threshold=9999999999)
Expand All @@ -7,19 +8,24 @@ def printAsCuMatMatrix(mat):
file = file + ']'
return file

n = 257

# for n in [300,400,500,750,1000]:
n = 10
dim = (n,n)

x = np.ones(dim) * 2.1
# y = np.identity(dim[0]) * 1

programHeader = "func int main { a = "
programHeader = "func float[" + str(n) + "," + str(n) + "] main { a = "
programHeader = programHeader + printAsCuMatMatrix(x).replace("\n", "")
programHeader = programHeader + "\n"
programHeader = programHeader + "return a .* a"
programHeader = programHeader + "return a * a"
programHeader = programHeader + "}"
text_file = open("pythonoutput.cm", "w")

text_file.write(programHeader)

text_file.close()
text_file.close()

os.system("cp pythonoutput.cm ../cmake-build-debug/src/compiler/src/python.cm")
os.system("cp pythonoutput.cm ../cmake-build-debug/src/compiler/src/python.cm")
Binary file added cudaBLAS/precompiled-cpu/10.cmProgram
Binary file not shown.
Binary file added cudaBLAS/precompiled-cpu/100.cmProgram
Binary file not shown.
Binary file added cudaBLAS/precompiled-cpu/1000.cmProgram
Binary file not shown.
Binary file added cudaBLAS/precompiled-cpu/150.cmProgram
Binary file not shown.
Binary file added cudaBLAS/precompiled-cpu/2.cmProgram
Binary file not shown.
Binary file added cudaBLAS/precompiled-cpu/20.cmProgram
Binary file not shown.
Binary file added cudaBLAS/precompiled-cpu/200.cmProgram
Binary file not shown.
Binary file added cudaBLAS/precompiled-cpu/250.cmProgram
Binary file not shown.
Binary file added cudaBLAS/precompiled-cpu/300.cmProgram
Binary file not shown.
Binary file added cudaBLAS/precompiled-cpu/4.cmProgram
Binary file not shown.
Binary file added cudaBLAS/precompiled-cpu/40.cmProgram
Binary file not shown.
Binary file added cudaBLAS/precompiled-cpu/400.cmProgram
Binary file not shown.
Binary file added cudaBLAS/precompiled-cpu/500.cmProgram
Binary file not shown.
Binary file added cudaBLAS/precompiled-cpu/6.cmProgram
Binary file not shown.
Binary file added cudaBLAS/precompiled-cpu/60.cmProgram
Binary file not shown.
Binary file added cudaBLAS/precompiled-cpu/750.cmProgram
Binary file not shown.
Binary file added cudaBLAS/precompiled-cpu/8.cmProgram
Binary file not shown.
Binary file added cudaBLAS/precompiled-cpu/80.cmProgram
Binary file not shown.
Binary file removed cudaBLAS/test
Binary file not shown.
16 changes: 12 additions & 4 deletions cudaBLAS/timer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import time
import os

start = time.perf_counter()
os.system("./CuMat-testBasic.cmProgram")
end = time.perf_counter()
print(end-start)
# start = time.perf_counter()
# os.system("./CuMat-testBasic.cmProgram")
# end = time.perf_counter()
# print(end-start)
files = [2,4,6,8,10,20,40,60,80,100,150,200,250,300,400,500,750,1000]
for i in files:
filename = "./precompiled-cpu/" + str(i) + ".cmProgram"
start = time.perf_counter()
os.system(filename)
end = time.perf_counter()
timetaken = (end-start) * 1000
print(f"Took: {timetaken}")
4 changes: 4 additions & 0 deletions src/compiler/inc/CompilerOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ enum class WARNINGS { ALL, INFO, NONE };

enum class OPTIMISATION { NONE, ALL, EXPERIMENTAL };

enum class COMPUTATION {AUTO, GPU, CPU};

class CompilerOptions {
public:
WARNINGS warningVerbosity = WARNINGS::NONE;

OPTIMISATION optimisationLevel = OPTIMISATION::ALL;

COMPUTATION computationMode = COMPUTATION::AUTO;

std::string inputFile;

std::string outputFile; // Default to name of file
Expand Down
24 changes: 23 additions & 1 deletion src/compiler/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main(int argc, char* argv[], char* envp[]) {
std::string inputFileName;
std::string outputFile;

const std::set<std::string> validFlags = {"-Wall", "-Winfo", "-Wnone", "-Oall", "-Onone", "-Oexp", "-o", "-s"};
const std::set<std::string> validFlags = {"-Wall", "-Winfo", "-Wnone", "-Mauto", "-Mcpu", "-Mgpu", "-Oall", "-Onone", "-Oexp", "-o", "-s"};

// First argument is always name of exe, ignore
for (int i = 1; i < argc; ++i) {
Expand Down Expand Up @@ -95,6 +95,28 @@ int main(int argc, char* argv[], char* envp[]) {
co.silent = true;
}

// Assign GPU / CPU / Auto mode
std::vector<std::string> compMode;
std::copy_if(args.begin(), args.end(), std::back_inserter(warningLevels),
[](std::string s) { return s.rfind("-M", 0) == 0; });
if (warningLevels.size() > 1) {
printArgumentError("Maximum of one computation mode should be set", "");
return 1;
}
if (warningLevels.size() == 1) {
auto warn = warningLevels.front();
if (warn == "-Mgpu") {
co.computationMode = COMPUTATION::GPU;
} else if (warn == "-Mcpu") {
co.computationMode = COMPUTATION::CPU;
} else if (warn == "-Mauto") {
co.computationMode = COMPUTATION::AUTO;
} else { // This shouldn't happen, but for completeness
printArgumentError("Unrecognised computation level", warn);
return 1; // Quit early
}
}

// Assign Optimisation level
std::vector<std::string> optimiseLevels;
std::copy_if(args.begin(), args.end(), std::back_inserter(optimiseLevels),
Expand Down
5 changes: 4 additions & 1 deletion src/parser/inc/DimensionPass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@

#include "ASTNode.hpp"

void dimension_error(const std::string& message, AST::Node* node);
void dimension_error(const std::string& message, AST::Node* node);
bool expandableDimensionMatrix(const Typing::MatrixType& left, const Typing::MatrixType& right);
bool expandableDimension(const Typing::Type& left, const Typing::Type& right);
std::vector<uint> expandedDimension(const Typing::MatrixType& left, const Typing::MatrixType& right);
1 change: 1 addition & 0 deletions src/parser/inc/ExprASTNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ class ExprNode : public Node {
std::shared_ptr<AST::ExprNode>& me) const {
throw std::runtime_error("attempt to access constData on non-const node");
};
[[nodiscard]] virtual bool isLiteralNode() const noexcept { return false; };
};
} // namespace AST
2 changes: 2 additions & 0 deletions src/parser/inc/LiteralNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ class LiteralNode : public ExprNode {
std::shared_ptr<AST::ExprNode>& me) const override {
return std::vector<std::shared_ptr<AST::ExprNode>>{me};
}

[[nodiscard]] bool isLiteralNode() const noexcept override { return true; };
};
} // namespace AST
4 changes: 3 additions & 1 deletion src/parser/inc/ProgramNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace AST {
class ProgramNode : public Node {
public:
llvm::Value* codeGen(Utils::IRContext* context) override;
[[nodiscard]] std::string toTree(const std::string& prefix, const std::string& childPrefix) const override{};
[[nodiscard]] std::string toTree(const std::string& prefix, const std::string& childPrefix) const override {
return std::string{};
};
void dimensionPass(Analysis::DimensionSymbolTable* nt) override;
};
} // namespace AST
4 changes: 3 additions & 1 deletion src/parser/inc/SliceNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class SliceNode : public Node {
void semanticPass(Utils::IRContext* context) override;

llvm::Value* codeGen(Utils::IRContext* context) override;
[[nodiscard]] std::string toTree(const std::string& prefix, const std::string& childPrefix) const override{};
[[nodiscard]] std::string toTree(const std::string& prefix, const std::string& childPrefix) const override {
return std::string{};
};
};
} // namespace AST
4 changes: 3 additions & 1 deletion src/parser/inc/TernaryExprNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class TernaryExprNode : public ExprNode {
void semanticPass(Utils::IRContext* context) override;
llvm::Value* codeGen(Utils::IRContext* context) override;
void dimensionPass(Analysis::DimensionSymbolTable* nt) override;
[[nodiscard]] std::string toTree(const std::string& prefix, const std::string& childPrefix) const override{};
[[nodiscard]] std::string toTree(const std::string& prefix, const std::string& childPrefix) const override {
return std::string{};
};
};
} // namespace AST
4 changes: 3 additions & 1 deletion src/parser/inc/UnaryExprNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class UnaryExprNode : public ExprNode {
llvm::Value* codeGen(Utils::IRContext* context) override;

bool shouldExecuteGPU(Utils::IRContext* context, UNA_OPERATORS op);
[[nodiscard]] std::string toTree(const std::string& prefix, const std::string& childPrefix) const override{};
[[nodiscard]] std::string toTree(const std::string& prefix, const std::string& childPrefix) const override {
return std::string{};
};
void dimensionPass(Analysis::DimensionSymbolTable* nt) override;
};
} // namespace AST
4 changes: 3 additions & 1 deletion src/parser/inc/VariableNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class VariableNode : public ExprNode {
llvm::Value* codeGen(Utils::IRContext* context) override;

llvm::Value* handleSlicing(Utils::IRContext* context, llvm::Value* val);
[[nodiscard]] std::string toTree(const std::string& prefix, const std::string& childPrefix) const override{};
[[nodiscard]] std::string toTree(const std::string& prefix, const std::string& childPrefix) const override {
return std::string{};
};
};
} // namespace AST
8 changes: 6 additions & 2 deletions src/parser/samples/testBasic.cm
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
func int main {
return 1 + 2
func int test(int[*] x) {
return if x == 1 then 2 else 3
}

func int[*] main {
return test (1)
}
7 changes: 7 additions & 0 deletions src/parser/src/ASTNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ std::string Node::toTree(const std::string& prefix, const std::string& childPref
return str;
}

void Node::dimensionPass(Analysis::DimensionSymbolTable* nt) {
for (auto const& child : this->children) child->dimensionPass(nt);
}
void Node::dimensionNamePass(Analysis::DimensionSymbolTable* nt) {
for (auto const& child : this->children) child->dimensionNamePass(nt);
}

} // namespace AST
32 changes: 22 additions & 10 deletions src/parser/src/AssignmentNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ llvm::Value* AST::AssignmentNode::codeGen(Utils::IRContext* context) {

// Ensure that matrix literals are upcast
if(auto* rValType = std::get_if<Typing::MatrixType>(&*rVal->type)){
if(rValType->rank == 0){
if (this->rVal->isLiteralNode()) {
rValLLVM = Utils::upcastLiteralToMatrix(context, *rValType, rValLLVM);
}
}
Expand Down Expand Up @@ -112,13 +112,25 @@ llvm::Value* AST::AssignmentNode::decompAssign(Utils::IRContext* context, std::s
auto matRecord = Utils::getMatrixFromPointer(context, matHeader);
// Calculate offset of the rVal data address

llvm::Value* rValDataPtr = context->Builder->CreateGEP(matRecord.dataPtr, lValMatRecord.numBytes, "rValOffset");
// llvm::Value* rValDataPtr = context->Builder->CreateGEP(matRecord.dataPtr, lValMatRecord.numBytes,
// "rValOffset");
// Point both of the data pointers to the correct locations
Utils::insertValueAtPointerOffset(context, lValMatRecord.dataPtr, 0, matRecord.dataPtr, false);
Utils::insertValueAtPointerOffset(context, rValMatRecord.dataPtr, 0, rValDataPtr, false);
auto* i32Ty = llvm::Type::getInt32Ty(context->module->getContext());
auto dataPtr = Utils::getPointerAddressFromOffset(context, matRecord.dataPtr, llvm::ConstantInt::get(i32Ty, 0));
auto secondDimDataPtr = Utils::getPointerAddressFromOffset(context, matRecord.dataPtr,
llvm::ConstantInt::get(i32Ty, matType->dimensions[0]));
llvm::Value* firstSize = llvm::ConstantExpr::getMul(llvm::ConstantInt::get(i32Ty, matType->dimensions[0]),
llvm::ConstantInt::get(i32Ty, 8));
llvm::Value* secondSize =
llvm::ConstantExpr::getMul(llvm::ConstantExpr::getMul(llvm::ConstantInt::get(i32Ty, matType->dimensions[0]),
llvm::ConstantInt::get(i32Ty, matType->rank - 1)),
llvm::ConstantInt::get(i32Ty, 8));
context->Builder->CreateMemCpy(
lValMatRecord.dataPtr, lValMatRecord.dataPtr->getPointerAlignment(context->module->getDataLayout()), dataPtr,
dataPtr->getPointerAlignment(context->module->getDataLayout()), firstSize);

// Handle assignment symbol table code
if (!context->symbolTable->inSymbolTable(this->name, context->symbolTable->getCurrentFunction())) {
if (!context->symbolTable->inSymbolTable(decomp->lVal, context->symbolTable->getCurrentFunction())) {
// Something has gone wrong during the parse stage and we have not added the symbol into the table
// Raising a warning!
if (context->compilerOptions->warningVerbosity == WARNINGS::ALL) {
Expand All @@ -128,16 +140,16 @@ llvm::Value* AST::AssignmentNode::decompAssign(Utils::IRContext* context, std::s
<< std::endl;
}
// No typing information can be inferred at this stage (nullptr) - Can and will cause issues hence the warning
context->symbolTable->setValue(nullptr, lValMatAlloc, this->name, context->symbolTable->getCurrentFunction());
context->symbolTable->setValue(nullptr, lValMatAlloc, decomp->lVal, context->symbolTable->getCurrentFunction());
} else {
context->symbolTable->updateValue(lValMatAlloc, this->name, context->symbolTable->getCurrentFunction());
context->symbolTable->updateValue(lValMatAlloc, decomp->lVal, context->symbolTable->getCurrentFunction());
}

// Handle any of the sub decompositions, these are not returned as we are not reducing the dimensions of them and we
// only pick the first variable assigned, but they will be present within the symbol table
std::shared_ptr<DecompNode> nestedDecomp = *std::get_if<std::shared_ptr<DecompNode>>(&decomp->rVal);
if (nestedDecomp) {
decompAssign(context, nestedDecomp, lValMatAlloc);

if (auto nestedDecomp = std::get_if<std::shared_ptr<DecompNode>>(&decomp->rVal)) {
decompAssign(context, *nestedDecomp, lValMatAlloc);
}
return lValMatAlloc; // Dunno, seems to be what I would want, maybe change?
}
Expand Down
Loading