-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
206 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import sparse | ||
|
||
import numpy as np | ||
|
||
from .utils import SkipNotImplemented | ||
|
||
TIMEOUT: float = 180.0 | ||
BACKEND: sparse.BackendType = sparse.backend_var.get() | ||
|
||
|
||
class Tensordot: | ||
timeout = TIMEOUT | ||
|
||
def setup(self): | ||
rng = np.random.default_rng(0) | ||
|
||
random_kwargs = {"density": 0.01, "random_state": rng} | ||
if sparse.BackendType.PyData == BACKEND: | ||
random_kwargs["format"] = "gcxs" | ||
|
||
self.s1 = sparse.random((100, 10), **random_kwargs) | ||
self.s2 = sparse.random((100, 100, 10), **random_kwargs) | ||
|
||
if sparse.BackendType.Finch == BACKEND: | ||
import finch | ||
|
||
self.s1 = self.s1.to_device( | ||
finch.Storage(finch.Dense(finch.SparseList(finch.Element(0.0))), order=self.s1.get_order()) | ||
) | ||
self.s2 = self.s2.to_device( | ||
finch.Storage( | ||
finch.Dense(finch.SparseList(finch.SparseList(finch.Element(0.0)))), | ||
order=self.s2.get_order(), | ||
) | ||
) | ||
|
||
sparse.tensordot(self.s1, self.s2, axes=([0, 1], [0, 2])) # compilation | ||
|
||
def time_tensordot(self): | ||
sparse.tensordot(self.s1, self.s2, axes=([0, 1], [0, 2])) | ||
|
||
|
||
class SpMv: | ||
timeout = TIMEOUT | ||
params = [[True, False], [(1000, 0.01), (1000, 0.01)]] # (1_000_000, 1e-05) | ||
param_names = ["lazy_mode", "size_and_density"] | ||
|
||
def setup(self, lazy_mode, size_and_density): | ||
rng = np.random.default_rng(0) | ||
size, density = size_and_density | ||
|
||
random_kwargs = {"density": density, "random_state": rng} | ||
if sparse.BackendType.PyData == BACKEND: | ||
random_kwargs["format"] = "gcxs" | ||
random_kwargs = {"density": density, "random_state": rng} | ||
|
||
self.M = sparse.random((size, size), **random_kwargs) | ||
self.v1 = rng.normal(size=(size, 2)) | ||
self.v2 = rng.normal(size=(size, 2)) | ||
|
||
if sparse.BackendType.Finch == BACKEND: | ||
import finch | ||
|
||
self.M = self.M.to_device( | ||
finch.Storage(finch.Dense(finch.SparseList(finch.Element(0.0))), order=self.M.get_order()) | ||
) | ||
self.v1 = finch.Tensor(self.v1) | ||
self.v2 = finch.Tensor(self.v2) | ||
if lazy_mode: | ||
|
||
@sparse.compiled | ||
def fn(tns1, tns2, tns3): | ||
return tns1 @ tns2 + tns3 | ||
else: | ||
|
||
def fn(tns1, tns2, tns3): | ||
return tns1 @ tns2 + tns3 | ||
|
||
elif sparse.BackendType.PyData == BACKEND: | ||
if lazy_mode: | ||
raise SkipNotImplemented("PyData doesn't have lazy mode") | ||
|
||
def fn(tns1, tns2, tns3): | ||
return tns1 @ tns2 + tns3 | ||
|
||
else: | ||
raise Exception(f"Invalid backend: {BACKEND}") | ||
|
||
self.fn = fn | ||
self.fn(self.M, self.v1, self.v2) | ||
|
||
def time_spmv(self, lazy_mode, size_and_density): | ||
self.fn(self.M, self.v1, self.v2) | ||
|
||
|
||
# class SDDMM: | ||
# timeout = TIMEOUT | ||
|
||
# def setup(): | ||
# pass | ||
|
||
# class Reductions: | ||
# timeout = TIMEOUT | ||
|
||
# def setup(): | ||
# pass | ||
|
||
# class Elemwise: | ||
# timeout = TIMEOUT | ||
|
||
# def setup(): | ||
# pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import os | ||
|
||
import sparse | ||
|
||
from asv_runner.benchmarks.mark import SkipNotImplemented | ||
|
||
|
||
def skip_if_finch(): | ||
if os.environ[sparse._ENV_VAR_NAME] == "Finch": | ||
raise SkipNotImplemented("Finch backend is skipped.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters