File size: 1,832 Bytes
5e9107e
26d582c
5e9107e
83dc985
5e9107e
83dc985
5e9107e
83dc985
 
 
 
b4c4327
 
 
 
bdbbc50
 
83dc985
 
 
 
 
 
 
 
 
 
 
 
 
b4c4327
83dc985
b4c4327
 
 
 
bdbbc50
 
83dc985
 
 
 
 
 
 
 
 
 
 
 
 
 
e328371
42642fd
b4c4327
 
 
 
791043c
 
42642fd
 
 
 
 
 
 
 
 
6936459
42642fd
e328371
5e9107e
9c22390
5e9107e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import gradio as gr
import spaces
import torch
import time

import numpy as np


print(f"torch_version: {torch.__version__}")

# Define two matrices using NumPy arrays
#A = np.array([[1, 2], [3, 4]])
#B = np.array([[5, 6], [7, 8]])

# Define large matrices
A = np.random.rand(10000, 10000)  # Random 10000x10000 matrix
B = np.random.rand(10000, 10000)

# Start the timer
start_time = time.time()

# Perform matrix multiplication
result = np.dot(A, B)

# End the timer
end_time = time.time()

# Calculate and print the time taken
print(f"Time taken for matrix multiplication with NumPy: {end_time - start_time:.6f} seconds")


# Define two matrices
#A = torch.tensor([[1, 2], [3, 4]])
#B = torch.tensor([[5, 6], [7, 8]])

# Define large matrices
A = torch.rand(10000, 10000)  # Random 10000x10000 matrix
B = torch.rand(10000, 10000)

# Start the timer
start_time = time.time()

# Perform matrix multiplication
result = torch.matmul(A, B)

# End the timer
end_time = time.time()

# Calculate and print the time taken
print(f"Time taken for matrix multiplication with PyTorch: {end_time - start_time:.6f} seconds")

@spaces.GPU
def zeroGPU_test(text):
    # Define two matrices
    #A = torch.tensor([[1, 2], [3, 4]])
    #B = torch.tensor([[5, 6], [7, 8]])

    # Define large matrices
    A = torch.rand(10000, 10000).to('cuda')   # Random 10000x10000 matrix
    B = torch.rand(10000, 10000).to('cuda') 
    
    # Start the timer
    start_time = time.time()
    
    # Perform matrix multiplication
    result = torch.matmul(A, B)
    
    # End the timer
    end_time = time.time()
    print(f"Time taken for matrix multiplication with GPU: {end_time - start_time:.6f} seconds")
    return f"Time: {end_time - start_time:.6f} seconds"
     

demo = gr.Interface(fn=zeroGPU_test, inputs=gr.Text(), outputs=gr.Text())
demo.launch()