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
4 changes: 2 additions & 2 deletions frontends/comet_dsl/comet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ int loadAndProcessMLIR(mlir::MLIRContext &context,
/// Check if there are missing tensor declaration operations introduced by compound expressions.
/// If so, add a new tensor declaration to represent intermediate tensors
/// =============================================================================
optPM.addPass(mlir::comet::createTensorAlgebraCheckImplicitTensorDeclPass());
// optPM.addPass(mlir::comet::createTensorAlgebraCheckImplicitTensorDeclPass());
/// =============================================================================
/// Check to see if we are dumping to TA dialect.
if (emitTA)
Expand Down Expand Up @@ -467,7 +467,7 @@ int loadAndProcessMLIR(mlir::MLIRContext &context,
/// Concretize the domains of all the index variables
optPM.addPass(mlir::comet::createIndexTreeDomainConcretizationPass());

if (OptKernelFusion || OptDimensionReduction)
if (OptDimensionReduction)
{
/// Reduce intermediate tensors' dimension after kernel fusion
optPM.addPass(mlir::comet::createIndexTreeDimensionReductionPass());
Expand Down
303 changes: 178 additions & 125 deletions frontends/comet_dsl/mlir/MLIRGen.cpp

Large diffs are not rendered by default.

173 changes: 103 additions & 70 deletions frontends/numpy-scipy/cometpy/MLIRGen/ops.py

Large diffs are not rendered by default.

263 changes: 189 additions & 74 deletions frontends/numpy-scipy/cometpy/comet.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,33 @@
import numpy as np

@comet.compile(flags="")
def comet_chain_multiply(A,B,C,D):
# res = comet.einsum('ij,jk,kl,lm->im', A, C, B, C.transpose()) @ D
res = A @ C @ B @ C.transpose() @ D
def comet_chain_multiply_in_place(A,B,C,D,E):
E[:] = A @ C @ B @ C.transpose() @ D

return res
@comet.compile(flags="")
def comet_chain_multiply_return(A,B,C,D):
return A @ C @ B @ C.transpose() @ D

def numpy_chain_multiply(A,B,C,D):
# res = np.einsum('ij,jk,kl,lm->im', A, C, B, C.transpose()) @ D
res = A @ C @ B @ C.transpose() @ D

return A @ C @ B @ C.transpose() @ D

return res

def test_Dense_chain_mult():
def init():
A = np.full([2,4], 1.0)
B = np.full([4,4], 1.0)
C = np.full([4,4], 1.0)
D = np.full([4,6], 1.0)
Enp = numpy_chain_multiply(A,B,C,D)

return A, B, C, D, Enp

Dn = numpy_chain_multiply(A,B,C,D)
Dc = comet_chain_multiply(A,B,C,D)
def test_Dense_chain_mult_in_place():
A, B, C, D, Enp = init()
Ecp = np.full([2,6], 0.0)
comet_chain_multiply_in_place(A,B,C,D,Ecp)
np.testing.assert_almost_equal(Ecp,Enp)

np.testing.assert_almost_equal(Dn,Dc)
def test_Dense_chain_mult_return():
A, B, C, D, Enp = init()
Ecp = comet_chain_multiply_return(A,B,C,D)
np.testing.assert_almost_equal(Ecp,Enp)
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
import time
import numpy as np
import scipy as sp
from cometpy import comet

def run_numpy(A,B):
C =B * A.transpose()
return B * A.transpose()

return C
@comet.compile()
def run_comet_return(A,B):
return B * A.transpose()

@comet.compile(flags=None)
def run_comet_with_jit(A,B):
C = B * A.transpose()
@comet.compile()
def run_comet_in_place(A,B,C):
C[:] = B * A.transpose()

return C

def test_Dense_eltwise_dTranspose():
def init():
A = np.full([4, 4], 3.2, dtype=float)
B = np.full([4, 4], 2.0, dtype=float)
C = np.full([4, 4], 0.0, dtype=float)
expected_result = run_numpy(A, B)
result_with_jit = run_comet_with_jit(A, B)
if sp.sparse.issparse(expected_result):
expected_result = expected_result.todense()
result_with_jit = result_with_jit.todense()
np.testing.assert_almost_equal(result_with_jit, expected_result)
Cnp = run_numpy(A, B)
return A, B, Cnp

def test_Dense_eltwise_dTranspose_in_place():
A, B, Cnp = init()
Ccp = np.full([4, 4], 0.0, dtype=float)
run_comet_in_place(A, B, Ccp)
np.testing.assert_almost_equal(Cnp, Ccp)

def test_Dense_eltwise_dTranspose_return():
A, B, Cnp = init()
Ccp = run_comet_return(A, B)
np.testing.assert_almost_equal(Cnp, Ccp)
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import time
import numpy as np
import scipy as sp
from cometpy import comet

def run_numpy(A,B):
C = A @ B.transpose()

return C

@comet.compile(flags=None)
def run_comet_with_jit(A,B):
C = A @ B.transpose()
@comet.compile()
def run_comet_return(A,B):
return A @ B.transpose()

return C
@comet.compile()
def run_comet_in_place(A,B,C):
C[:] = A @ B.transpose()

def test_Dense_mult_dTranspose():
B = np.full([5, 5], 3.2, dtype=float)
def init():
A = np.full([5, 5], 2.3, dtype=float)
C = np.full([5, 5], 0.0, dtype=float)
expected_result = run_numpy(A,B)
result_with_jit = run_comet_with_jit(A,B)
if sp.sparse.issparse(expected_result):
expected_result = expected_result.todense()
result_with_jit = result_with_jit.todense()
np.testing.assert_almost_equal(result_with_jit, expected_result)
B = np.full([5, 5], 3.2, dtype=float)
Cnp = run_numpy(A, B)
return A, B, Cnp

def test_Dense_mult_dTranspose_return():
A, B, Cnp = init()
Ccp = run_comet_return(A,B)
np.testing.assert_almost_equal(Ccp, Cnp)

def test_Dense_mult_dTranspose_in_place():
A, B, Cnp = init()
Ccp = np.full([5, 5], 0.0, dtype=float)
run_comet_in_place(A,B, Ccp)
np.testing.assert_almost_equal(Ccp, Cnp)
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
import time
import numpy as np
import scipy as sp
from cometpy import comet
import pytest

def run_numpy(A, B):
C = A.transpose() * B

return C

@comet.compile(flags=None)
def run_comet_with_jit(A, B):
C = A.transpose() * B
@comet.compile()
def run_comet_return(A, B):
return A.transpose() * B

return C
@comet.compile()
def run_comet_in_place(A, B, C):
C[:] = A.transpose() * B

def test_dTranspose_eltwise_CSR(data_rank2_path):
def init(data_rank2_path):
B = sp.sparse.csr_array(sp.io.mmread(data_rank2_path))
A = np.full([B.shape[1], B.shape[0]], 3.2, dtype=float)
expected_result = run_numpy(A, B)
result_with_jit = run_comet_with_jit(A, B)
if sp.sparse.issparse(expected_result):
expected_result = expected_result.todense()
if sp.sparse.issparse(result_with_jit):
result_with_jit = result_with_jit.todense()
np.testing.assert_almost_equal(result_with_jit, expected_result)
Cnp = run_numpy(A, B)
return A, B, Cnp

def test_dTranspose_eltwise_CSR_return(data_rank2_path):
A, B, Cnp = init(data_rank2_path)
Ccp = run_comet_return(A, B)
if sp.sparse.issparse(Cnp):
Cnp = Cnp.todense()
if sp.sparse.issparse(Ccp):
Ccp = Ccp.todense()
np.testing.assert_almost_equal(Ccp, Cnp)

@pytest.mark.skip('In place mutation of sparse matrices is not supported yet')
def test_dTranspose_eltwise_CSR_in_place(data_rank2_path):
A, B, Cnp = init(data_rank2_path)
Ccp = sp.sparse.csr_array((B.shape[0], B.shape[1]), dtype = float)
run_comet_in_place(A, B, Ccp)
if sp.sparse.issparse(Cnp):
Cnp = Cnp.todense()
if sp.sparse.issparse(Ccp):
Ccp = Ccp.todense()
np.testing.assert_almost_equal(Ccp, Cnp)
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
import time
import numpy as np
import scipy as sp
from cometpy import comet

def run_numpy(A, B):
C = A.transpose() * B
def run_numpy(A,B):
return A.transpose() * B

return C
@comet.compile(flags=None)
def run_comet_return(A,B,C):
return A.transpose() * B

@comet.compile(flags=None)
def run_comet_with_jit(A, B):
C = A.transpose() * B
def run_comet_in_place(A,B,C):
C[:] = A.transpose() * B

return C

def test_dTranspose_eltwise_Dense():
def init():
A = np.full([4, 4], 3.2, dtype=float)
B = np.full([4, 4], 2.0, dtype=float)
C = np.full([4, 4], 0.0, dtype=float)
expected_result = run_numpy(A, B)
result_with_jit = run_comet_with_jit(A, B)
if sp.sparse.issparse(expected_result):
expected_result = expected_result.todense()
result_with_jit = result_with_jit.todense()
np.testing.assert_almost_equal(result_with_jit, expected_result)
B = np.full([4, 4], 2.0, dtype=float)
Cnp = run_numpy(A, B)
return A, B, Cnp

def test_dTranspose_eltwise_Dense_in_place():
A, B, Cnp = init()
Ccp = np.full([4, 4], 0.0, dtype=float)
run_comet_in_place(A, B, Ccp)
np.testing.assert_almost_equal(Ccp, Cnp)

def test_dTranspose_eltwise_Dense_return():
A, B, Cnp = init()
Ccp = run_comet_return(A, B)
np.testing.assert_almost_equal(Ccp, Cnp)
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import time
import numpy as np
import scipy as sp
from cometpy import comet
Expand All @@ -8,19 +7,35 @@ def run_numpy(A, B):

return C

@comet.compile(flags=None)
def run_comet_with_jit(A, B):
C = A.transpose() @ B
@comet.compile()
def run_comet_return(A, B):
return A.transpose() @ B

return C
@comet.compile()
def run_comet_in_place(A, B, C):
C[:] = A.transpose() @ B

def test_dTranspose_mult_CSR(data_rank2_path):
def init(data_rank2_path):
B = sp.sparse.csr_array(sp.io.mmread(data_rank2_path))
A = np.full([B.shape[0], 4], 1.7, dtype=float)
C = np.full([4, B.shape[1]], 0.0, dtype=float)
expected_result = run_numpy(A, B)
result_with_jit = run_comet_with_jit(A, B)
if sp.sparse.issparse(expected_result):
expected_result = expected_result.todense()
result_with_jit = result_with_jit.todense()
np.testing.assert_almost_equal(result_with_jit, expected_result)
Cnp = run_numpy(A, B)
return A, B, Cnp



def test_dTranspose_mult_CSR_in_place(data_rank2_path):
A, B, Cnp = init(data_rank2_path)
Ccp = np.full([4, B.shape[1]], 0.0, dtype=float)
run_comet_in_place(A, B, Ccp)
if sp.sparse.issparse(Cnp):
Cnp = Cnp.todense()
Ccp = Ccp.todense()
np.testing.assert_almost_equal(Ccp, Cnp)

def test_dTranspose_mult_CSR_return(data_rank2_path):
A, B, Cnp = init(data_rank2_path)
Ccp = run_comet_return(A, B)
if sp.sparse.issparse(Cnp):
Cnp = Cnp.todense()
Ccp = Ccp.todense()
np.testing.assert_almost_equal(Ccp, Cnp)
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import time
import numpy as np
import scipy as sp
from cometpy import comet

def run_numpy(A, B):
C = A.transpose() @ B
def run_numpy(A,B):
return A.transpose() @ B

return C
@comet.compile()
def run_comet_return(A,B):
return A.transpose() @ B

@comet.compile(flags=None)
def run_comet_with_jit(A, B):
C = A.transpose() @ B
@comet.compile()
def run_comet_in_place(A,B,C):
C[:] = A.transpose() @ B

return C

def test_dTranspose_mult_Dense():
def init():
A = np.full([4, 4], 3.2, dtype=float)
B = np.full([4, 4], 1.0, dtype=float)
C = np.full([4, 4], 0.0, dtype=float)
expected_result = run_numpy(A, B)
result_with_jit = run_comet_with_jit(A, B)
if sp.sparse.issparse(expected_result):
expected_result = expected_result.todense()
result_with_jit = result_with_jit.todense()
np.testing.assert_almost_equal(result_with_jit, expected_result)
Cnp = run_numpy(A, B)
return A, B, Cnp

def test_dTranspose_mult_Dense_in_place():
A, B, Cnp = init()
Ccp = np.full([4, 4], 0.0, dtype=float)
run_comet_in_place(A, B, Ccp)
np.testing.assert_almost_equal(Ccp, Cnp)

def test_dTranspose_mult_Dense_return():
A, B, Cnp = init()
Ccp = run_comet_return(A, B)
np.testing.assert_almost_equal(Ccp, Cnp)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def run_comet_with_jit(L0):
C = ((L0 @ L0) * L0).sum()
return C

@pytest.mark.skip(reason="Triangle counting currently fails")
def test_triangleCount_SandiaLL(data_tc_path):
A = sp.sparse.csr_array(sp.io.mmread(data_tc_path))
L0 = sp.sparse.csr_array(sp.sparse.tril(A, format='csr'))
Expand Down
4 changes: 1 addition & 3 deletions frontends/numpy-scipy/integration_tests/opts/test_fusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ def run_comet_with_jit(B,C,D):

return A

@pytest.mark.skip("Fusing more than one iterations is not currently supported")
def test_fusion(data_rank2_path):
B = sp.sparse.csr_array(sp.io.mmread(data_rank2_path))
C = np.full([B.shape[1], 4], 1.2, dtype=float)
D = np.full([4, 4], 3.4, dtype=float)
A = np.full([B.shape[0], 4], 0.0, dtype=float)
T = np.full([B.shape[0], 4], 0.0, dtype=float)

expected_result = run_numpy(B,C,D)
result_with_jit = run_comet_with_jit(B,C,D)
if sp.sparse.issparse(expected_result):
Expand Down
Loading