Last active
June 12, 2019 06:33
-
-
Save okapies/a6a9d8adbbb29b680f4e78cca44e7221 to your computer and use it in GitHub Desktop.
Revisions
-
okapies revised this gist
Jun 12, 2019 . 1 changed file with 10 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -60,11 +60,20 @@ def time_cupy(number, f, *args, **kwargs): start = stream.record() for i in range(number): f(*args, **kwargs) end = stream.record() stream.synchronize() return cupy.cuda.get_elapsed_time(start, end) / 1000 def time_chainerx(number, device, f, *args, **kwargs): start = time.time() for i in range(number): f(*args, **kwargs) device.synchronize() end = time.time() return end - start def main(): args = parser.parse_args() xp, a = setup(args) -
okapies revised this gist
Mar 19, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -60,8 +60,8 @@ def time_cupy(number, f, *args, **kwargs): start = stream.record() for i in range(number): f(*args, **kwargs) stream.synchronize() end = stream.record() return cupy.cuda.get_elapsed_time(start, end) / 1000 -
okapies renamed this gist
Mar 6, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
okapies revised this gist
Mar 6, 2019 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,6 @@ $ python xp_nested_array.py --src-xp numpy --dst-xp numpy --shape "(3, 224, 224)" --batch-size 10 Shape: (3, 224, 224) Batch size: 10 Running numpy.array(<List[numpy.ndarray]>) in 10000 times... 3.857709832955152 ``` This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -42,7 +42,7 @@ def setup(args): print("Shape: " + str(shape)) print("Batch size: " + str(batch_size)) print("Running " + dst_xp.__name__ + ".array(<List[" + str(src_xp.__name__) + ".ndarray]>) in " + str(number) + " times...") return (dst_xp, a) -
okapies revised this gist
Mar 6, 2019 . 2 changed files with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,6 @@ $ python xp_nested_array.py --src-xp numpy --dst-xp numpy --shape "(3, 224, 224)" --batch-size 10 Shape: (3, 224, 224) Batch size: 10 Running numpy.array(List[numpy]) in 10000 times... 3.857709832955152 ``` This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -42,7 +42,7 @@ def setup(args): print("Shape: " + str(shape)) print("Batch size: " + str(batch_size)) print("Running " + dst_xp.__name__ + ".array(List[" + str(src_xp.__name__) + "]) in " + str(number) + " times...") return (dst_xp, a) -
okapies revised this gist
Mar 6, 2019 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ import argparse import ast import functools import gc import operator import time @@ -14,6 +15,7 @@ parser.add_argument('--dst-xp', type=str, choices=["numpy", "cupy"], required=True) parser.add_argument('--shape', type=str, default="(1,)") parser.add_argument('--batch-size', type=int, default=1) parser.add_argument('--debug', action='store_true') def to_xp(s): @@ -28,8 +30,8 @@ def to_xp(s): def setup(args): src_xp = to_xp(args.src_xp) dst_xp = to_xp(args.dst_xp) shape = ast.literal_eval(args.shape) size = functools.reduce(operator.mul, shape, 1) batch_size = args.batch_size number = args.number -
okapies revised this gist
Mar 6, 2019 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,6 @@ $ python xp_nested_array.py --src-xp numpy --dst-xp numpy --shape "(3, 224, 224)" --batch-size 10 Shape: (3, 224, 224) Batch size: 10 Running numpy.array(<numpy>) in 10000 times... 3.857709832955152 ``` This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -40,7 +40,7 @@ def setup(args): print("Shape: " + str(shape)) print("Batch size: " + str(batch_size)) print("Running " + dst_xp.__name__ + ".array(<" + str(src_xp.__name__) + ">) in " + str(number) + " times...") return (dst_xp, a) -
okapies revised this gist
Mar 6, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -10,8 +10,8 @@ parser = argparse.ArgumentParser() parser.add_argument('--number', type=int, default=10000) parser.add_argument('--src-xp', type=str, choices=["numpy", "cupy"], required=True) parser.add_argument('--dst-xp', type=str, choices=["numpy", "cupy"], required=True) parser.add_argument('--shape', type=str, default="(1,)") parser.add_argument('--batch-size', type=int, default=1) -
okapies revised this gist
Mar 6, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -10,8 +10,8 @@ parser = argparse.ArgumentParser() parser.add_argument('--number', type=int, default=10000) parser.add_argument('--src-xp', type=str, choices=["numpy", "cupy"]) parser.add_argument('--dst-xp', type=str, choices=["numpy", "cupy"]) parser.add_argument('--shape', type=str, default="(1,)") parser.add_argument('--batch-size', type=int, default=1) -
okapies revised this gist
Mar 6, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -33,6 +33,7 @@ def setup(args): batch_size = args.batch_size number = args.number # e.g. a = [src_xp.array([[0, 1], [2, 3]]), src_xp.array([[4, 5], [6, 7]])] a = [ src_xp.array(range(i*size, (i+1)*size), dtype=src_xp.float32).reshape(shape) for i in range(batch_size)] -
okapies revised this gist
Mar 6, 2019 . 1 changed file with 56 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,12 @@ import argparse from ast import literal_eval as make_tuple from functools import reduce import operator import time import numpy import cupy parser = argparse.ArgumentParser() parser.add_argument('--number', type=int, default=10000) @@ -8,36 +15,63 @@ parser.add_argument('--shape', type=str, default="(1,)") parser.add_argument('--batch-size', type=int, default=1) def to_xp(s): if s == 'numpy': return numpy if s == 'cupy': return cupy else: raise def setup(args): src_xp = to_xp(args.src_xp) dst_xp = to_xp(args.dst_xp) shape = make_tuple(args.shape) size = reduce(operator.mul, shape, 1) batch_size = args.batch_size number = args.number a = [ src_xp.array(range(i*size, (i+1)*size), dtype=src_xp.float32).reshape(shape) for i in range(batch_size)] print("Shape: " + str(shape)) print("Batch size: " + str(batch_size)) print("Run " + dst_xp.__name__ + ".array(<" + str(src_xp.__name__) + ">) in " + str(number) + " times...") return (dst_xp, a) def time_numpy(number, f, *args, **kwargs): start = time.time() for i in range(number): f(*args, **kwargs) end = time.time() return end - start def time_cupy(number, f, *args, **kwargs): stream = cupy.cuda.Stream.null start = stream.record() for i in range(number): f(*args, **kwargs) end = stream.record() end.synchronize() return cupy.cuda.get_elapsed_time(start, end) / 1000 def main(): args = parser.parse_args() xp, a = setup(args) if xp is numpy: print(time_numpy(args.number, xp.array, a)) elif xp is cupy: print(time_cupy(args.number, xp.array, a)) else: raise if __name__ == '__main__': main() -
okapies revised this gist
Mar 6, 2019 . 2 changed files with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,6 @@ $ python xp_nested_array.py --src-xp numpy --dst-xp numpy --shape "(3, 224, 224)" --batch-size 10 Shape: (3, 224, 224) Batch size: 10 Run numpy.array(<numpy>) in 10000 times... 3.857709832955152 ``` This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import timeit parser = argparse.ArgumentParser() parser.add_argument('--number', type=int, default=10000) parser.add_argument('--src-xp', type=str, choices=["numpy", "cupy"], default="numpy") parser.add_argument('--dst-xp', type=str, choices=["numpy", "cupy"], default="cupy") parser.add_argument('--shape', type=str, default="(1,)") -
okapies created this gist
Mar 6, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ ```bash $ python xp_nested_array.py --src-xp numpy --dst-xp numpy --shape "(3, 224, 224)" --batch-size 10 Shape: (3, 224, 224) Batch size: 10 Run numpy.array(<numpy>) in 100000 times... 39.108506463933736 ``` This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ import argparse import timeit parser = argparse.ArgumentParser() parser.add_argument('--number', type=int, default=100000) parser.add_argument('--src-xp', type=str, choices=["numpy", "cupy"], default="numpy") parser.add_argument('--dst-xp', type=str, choices=["numpy", "cupy"], default="cupy") parser.add_argument('--shape', type=str, default="(1,)") parser.add_argument('--batch-size', type=int, default=1) def setup(args): return """ from functools import reduce import operator import numpy import cupy src_xp = {} dst_xp = {} shape = {} size = reduce(operator.mul, shape, 1) batch_size = {} number = {} a = [ src_xp.array(range(i*size, (i+1)*size), dtype=src_xp.float32).reshape(shape) for i in range(batch_size)] print("Shape: " + str(shape)) print("Batch size: " + str(batch_size)) print("Run " + dst_xp.__name__ + ".array(<" + str(src_xp.__name__) + ">) in " + str(number) + " times...") """.format(args.src_xp, args.dst_xp, args.shape, args.batch_size, args.number) def stmt(args): return "dst_xp.array(a)" def main(): args = parser.parse_args() print(timeit.timeit(stmt(args), setup=setup(args), number=args.number)) if __name__ == '__main__': main()