Python: added some new examples
This commit is contained in:
17
python/examples/custom-context.py
Normal file
17
python/examples/custom-context.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import isaac as sc
|
||||||
|
|
||||||
|
N = 7
|
||||||
|
|
||||||
|
platforms = sc.driver.get_platforms()
|
||||||
|
devices = [d for platform in platforms for d in platform.get_devices()]
|
||||||
|
device = devices[0]
|
||||||
|
print 'Using', device.name, 'on', device.platform.name
|
||||||
|
|
||||||
|
context = sc.driver.context(device)
|
||||||
|
x = sc.empty(N, sc.float32, context)
|
||||||
|
y = sc.empty(N, sc.float32, context)
|
||||||
|
|
||||||
|
z, events = sc.driver.enqueue(x + y)
|
||||||
|
z.context.synchronize()
|
||||||
|
|
||||||
|
print z
|
25
python/examples/custom-operation.py
Normal file
25
python/examples/custom-operation.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import isaac as sc
|
||||||
|
import isaac.templates as templates
|
||||||
|
|
||||||
|
sc.driver.default.queue_properties = sc.driver.PROFILING_ENABLE
|
||||||
|
sc.driver.default.device = 0;
|
||||||
|
|
||||||
|
#Construct vectors using the default device.
|
||||||
|
M, N, K = 972, 1541, 793
|
||||||
|
A = sc.empty((M, K), sc.float32)
|
||||||
|
B = sc.empty((K, N), sc.float32)
|
||||||
|
|
||||||
|
#Get command queue
|
||||||
|
queue = A.context.queues[0]
|
||||||
|
|
||||||
|
#Benchmark profile 1
|
||||||
|
queue.profiles[sc.templates.gemm_nn, sc.float32] = sc.profile(templates.gemm_nn(1,8,16,8,1,8,1,8,templates.FETCH_FROM_LOCAL,templates.FETCH_FROM_LOCAL,8,8), sc.float32, queue)
|
||||||
|
C, events = sc.driver.enqueue(sc.dot(A, B))
|
||||||
|
C.context.synchronize()
|
||||||
|
print 'Profile 1 finished in', sum([e.elapsed_time for e in events])*1e-9, 's'
|
||||||
|
|
||||||
|
#Benchmark profile 2
|
||||||
|
queue.profiles[sc.templates.gemm_nn, sc.float32] = sc.profile(templates.gemm_nn(1,8,16,16,1,8,1,8,templates.FETCH_FROM_LOCAL,templates.FETCH_FROM_LOCAL,8,16), sc.float32, queue)
|
||||||
|
C, events = sc.driver.enqueue(sc.dot(A, B))
|
||||||
|
C.context.synchronize()
|
||||||
|
print 'Profile 2 finished in', sum([e.elapsed_time for e in events])*1e-9, 's'
|
10
python/examples/infos.py
Normal file
10
python/examples/infos.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import isaac as sc
|
||||||
|
|
||||||
|
platforms = sc.driver.get_platforms()
|
||||||
|
devices = [d for platform in platforms for d in platform.get_devices()]
|
||||||
|
print("----------------")
|
||||||
|
print("Devices available:")
|
||||||
|
print("----------------")
|
||||||
|
for (i, d) in enumerate(devices):
|
||||||
|
print '[', i, ']', '-', sc.driver.device_type_to_string(d.type), '-', d.name, 'on', d.platform.name
|
||||||
|
print("----------------")
|
Reference in New Issue
Block a user