Skip to content

Commit c02a061

Browse files
committed
更新了轻度修改的文件
1 parent e74243b commit c02a061

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+202675
-23055
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2+
"python.linting.pylintArgs": ["--generate-members"],
23
"python.pythonPath": "C:\\Users\\youqi\\AppData\\Local\\Programs\\Python\\Python37\\python.exe"
34
}

energy.txt

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
1985.5091552734375 -19378.7421875
2+
1984.4820556640625 -19377.71484375
3+
1985.6260986328125 -19378.84375
4+
1983.0394287109375 -19376.267578125
5+
1983.7828369140625 -19377.0078125
6+
1988.2161865234375 -19381.447265625
7+
1983.271484375 -19376.494140625
8+
1987.688720703125 -19380.919921875
9+
1983.4483642578125 -19376.6796875
10+
1984.353759765625 -19377.57421875
11+
1985.1253662109375 -19378.353515625
12+
1986.6646728515625 -19379.896484375
13+
1981.480712890625 -19374.7109375
14+
1981.3424072265625 -19374.568359375
15+
1984.409423828125 -19377.642578125
16+
1984.2510986328125 -19377.474609375
17+
1986.261962890625 -19379.494140625
18+
1981.527099609375 -19374.751953125
19+
1981.5015869140625 -19374.716796875
20+
1982.44873046875 -19375.673828125
21+
1985.4805908203125 -19378.6953125
22+
1982.7437744140625 -19375.96875
23+
1985.610595703125 -19378.83984375
24+
1984.3294677734375 -19377.548828125
25+
1987.9002685546875 -19381.1328125
26+
1985.5340576171875 -19378.765625
27+
1983.4188232421875 -19376.642578125
28+
1982.3707275390625 -19375.595703125
29+
1984.3631591796875 -19377.59375
30+
1985.065673828125 -19378.287109375
31+
1983.2916259765625 -19376.521484375
32+
1985.379150390625 -19378.611328125
33+
1985.020751953125 -19378.25390625
34+
1985.6441650390625 -19378.875
35+
1986.3995361328125 -19379.626953125
36+
1985.851806640625 -19379.0859375
37+
1983.0081787109375 -19376.23046875
38+
1989.343994140625 -19382.5859375
39+
1984.081787109375 -19377.310546875
40+
1985.724609375 -19378.955078125
41+
1981.987060546875 -19375.212890625
42+
1986.720703125 -19379.953125
43+
1982.69482421875 -19375.919921875
44+
1984.80224609375 -19378.02734375
45+
1988.1903076171875 -19381.4296875
46+
1987.8470458984375 -19381.07421875
47+
1984.8387451171875 -19378.072265625
48+
1985.5028076171875 -19378.7265625
49+
1984.982177734375 -19378.203125
50+
1981.2303466796875 -19374.4453125
51+
1986.169677734375 -19379.396484375
52+
1985.0145263671875 -19378.25390625
53+
1986.0494384765625 -19379.283203125
54+
1984.39697265625 -19377.615234375
55+
1984.2288818359375 -19377.447265625
56+
1984.7386474609375 -19377.96484375
57+
1984.123046875 -19377.345703125
58+
1986.0738525390625 -19379.3125
59+
1985.4046630859375 -19378.6328125
60+
1983.766357421875 -19376.97265625
61+
1986.3470458984375 -19379.56640625
62+
1982.435302734375 -19375.65625
63+
1981.8321533203125 -19375.064453125
64+
1984.8134765625 -19378.046875
65+
1982.1339111328125 -19375.36328125
66+
1980.41748046875 -19373.630859375
67+
1985.4794921875 -19378.71875
68+
1985.591796875 -19378.828125
69+
1985.119140625 -19378.34375
70+
1985.63525390625 -19378.865234375
71+
1984.6710205078125 -19377.904296875
72+
1983.0185546875 -19376.228515625
73+
1988.08056640625 -19381.298828125
74+
1986.974365234375 -19380.19140625
75+
1983.962158203125 -19377.173828125
76+
1986.1373291015625 -19379.34765625
77+
1983.072998046875 -19376.287109375
78+
1986.2454833984375 -19379.46484375
79+
1980.625 -19373.841796875
80+
1984.056396484375 -19377.28125
81+
1984.1539306640625 -19377.361328125
82+
1981.9901123046875 -19375.197265625
83+
1985.7548828125 -19378.96875
84+
1985.1204833984375 -19378.3359375
85+
1982.946044921875 -19376.158203125
86+
1982.4849853515625 -19375.69921875
87+
1983.982666015625 -19377.20703125
88+
1986.840087890625 -19380.056640625
89+
1982.8065185546875 -19376.017578125
90+
1985.6536865234375 -19378.87109375
91+
1982.5115966796875 -19375.724609375
92+
1985.1973876953125 -19378.41015625
93+
1982.3037109375 -19375.525390625
94+
1987.876953125 -19381.103515625
95+
1987.216552734375 -19380.42578125
96+
1984.2060546875 -19377.42578125
97+
1982.8623046875 -19376.076171875
98+
1983.5577392578125 -19376.7578125
99+
1985.5174560546875 -19378.744140625
100+
1985.1243896484375 -19378.341796875
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
There is no source code in this Chapter.
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import pycuda.autoinit
2-
import pycuda.driver as drv
3-
from pycuda.compiler import SourceModule
4-
5-
kernel_code = r"""
6-
__global__ void hello_from_gpu(void)
7-
{
8-
printf("hello World from the GPU!\n");
9-
}
10-
"""
11-
mod = SourceModule(kernel_code)
12-
hello_from_gpu = mod.get_function("hello_from_gpu")
13-
hello_from_gpu(grid=(1,1,1), block=(1,1,1))
1+
import pycuda.autoinit
2+
from pycuda.compiler import SourceModule
3+
4+
kernel_code = r"""
5+
__global__ void hello_from_gpu(void)
6+
{
7+
printf("Hello World from the GPU!\n");
8+
}
9+
"""
10+
mod = SourceModule(kernel_code)
11+
hello_from_gpu = mod.get_function("hello_from_gpu")
12+
hello_from_gpu(grid=(1,1,1), block=(1,1,1))
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import pycuda.autoinit
2-
import pycuda.driver as drv
3-
from pycuda.compiler import SourceModule
4-
5-
mod = SourceModule(r"""
6-
__global__ void hello_from_gpu(void)
7-
{
8-
printf("hello World from the GPU!\n");
9-
}
10-
""")
11-
12-
hello_from_gpu = mod.get_function("hello_from_gpu")
13-
hello_from_gpu(grid=(2,1,1),block=(4,1,1))
1+
import pycuda.autoinit
2+
import pycuda.driver as drv
3+
from pycuda.compiler import SourceModule
4+
5+
mod = SourceModule(r"""
6+
__global__ void hello_from_gpu(void)
7+
{
8+
printf("hello World from the GPU!\n");
9+
}
10+
""")
11+
12+
hello_from_gpu = mod.get_function("hello_from_gpu")
13+
hello_from_gpu(grid=(2,1,1),block=(4,1,1))
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import pycuda.autoinit
2-
import pycuda.driver as drv
3-
from pycuda.compiler import SourceModule
4-
5-
mod = SourceModule(r"""
6-
__global__ void hello_from_gpu(void)
7-
{
8-
const int bid = blockIdx.x;
9-
const int tid = threadIdx.x;
10-
printf("Hello World from block %d and thread %d!\n", bid, tid);
11-
}
12-
""")
13-
14-
hello_from_gpu = mod.get_function("hello_from_gpu")
15-
hello_from_gpu(grid=(2,1,1), block=(4,1,1))
1+
import pycuda.autoinit
2+
import pycuda.driver as drv
3+
from pycuda.compiler import SourceModule
4+
5+
mod = SourceModule(r"""
6+
__global__ void hello_from_gpu(void)
7+
{
8+
const int bid = blockIdx.x;
9+
const int tid = threadIdx.x;
10+
printf("Hello World from block %d and thread %d!\n", bid, tid);
11+
}
12+
""")
13+
14+
hello_from_gpu = mod.get_function("hello_from_gpu")
15+
hello_from_gpu(grid=(2,1,1), block=(4,1,1))
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import pycuda.autoinit
2-
import pycuda.driver as drv
3-
from pycuda.compiler import SourceModule
4-
5-
mod = SourceModule(r"""
6-
__global__ void hello_from_gpu(void)
7-
{
8-
const int b = blockIdx.x;
9-
const int tx = threadIdx.x;
10-
const int ty = threadIdx.y;
11-
printf("Hello World from block-%d and thread-(%d, %d)!\n", b, tx, ty);
12-
}
13-
""")
14-
15-
hello_from_gpu = mod.get_function("hello_from_gpu")
16-
hello_from_gpu(grid=(1,1,1), block=(2,4,1))
1+
import pycuda.autoinit
2+
import pycuda.driver as drv
3+
from pycuda.compiler import SourceModule
4+
5+
mod = SourceModule(r"""
6+
__global__ void hello_from_gpu(void)
7+
{
8+
const int b = blockIdx.x;
9+
const int tx = threadIdx.x;
10+
const int ty = threadIdx.y;
11+
printf("Hello World from block-%d and thread-(%d, %d)!\n", b, tx, ty);
12+
}
13+
""")
14+
15+
hello_from_gpu = mod.get_function("hello_from_gpu")
16+
hello_from_gpu(grid=(1,1,1), block=(2,4,1))
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import numpy
2-
3-
EPSILON = 1e-15
4-
a = 1.23
5-
b = 2.34
6-
c = 3.57
7-
N = 100000000
8-
x = numpy.full((N,1), a)
9-
y = numpy.full((N,1), b)
10-
z = x + y
11-
print('No errors' if (abs(z-c)<EPSILON).all() else 'Has errors')
1+
import numpy
2+
3+
EPSILON = 1e-15
4+
a = 1.23
5+
b = 2.34
6+
c = 3.57
7+
N = 100000000
8+
x = numpy.full((N,1), a)
9+
y = numpy.full((N,1), b)
10+
z = x + y
11+
print('No errors' if (abs(z-c)<EPSILON).all() else 'Has errors')
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import pycuda.autoinit
2-
import pycuda.driver as drv
3-
from pycuda.compiler import SourceModule
4-
import numpy
5-
6-
mod = SourceModule(r"""
7-
void __global__ add(const float *x, const float *y, float *z)
8-
{
9-
const int n = blockDim.x * blockIdx.x + threadIdx.x;
10-
z[n] = x[n] + y[n];
11-
}
12-
""")
13-
add = mod.get_function("add")
14-
15-
EPSILON = 1e-15
16-
a = 1.23
17-
b = 2.34
18-
c = 3.57
19-
N = 100000000
20-
h_x = numpy.full((N,1), a, dtype=numpy.float32)
21-
h_y = numpy.full((N,1), b, dtype=numpy.float32)
22-
h_z = numpy.zeros_like(h_x, dtype=numpy.float32)
23-
d_x = drv.mem_alloc(h_x.nbytes)
24-
d_y = drv.mem_alloc(h_y.nbytes)
25-
d_z = drv.mem_alloc(h_z.nbytes)
26-
drv.memcpy_htod(d_x, h_x)
27-
drv.memcpy_htod(d_y, h_y)
28-
add(d_x, d_y, d_z, grid=(N//128, 1), block=(128,1,1))
29-
drv.memcpy_dtoh(h_z, d_z)
1+
import pycuda.autoinit
2+
import pycuda.driver as drv
3+
from pycuda.compiler import SourceModule
4+
import numpy
5+
6+
mod = SourceModule(r"""
7+
void __global__ add(const float *x, const float *y, float *z)
8+
{
9+
const int n = blockDim.x * blockIdx.x + threadIdx.x;
10+
z[n] = x[n] + y[n];
11+
}
12+
""")
13+
add = mod.get_function("add")
14+
15+
EPSILON = 1e-15
16+
a = 1.23
17+
b = 2.34
18+
c = 3.57
19+
N = 100000000
20+
h_x = numpy.full((N,1), a, dtype=numpy.float32)
21+
h_y = numpy.full((N,1), b, dtype=numpy.float32)
22+
h_z = numpy.zeros_like(h_x, dtype=numpy.float32)
23+
d_x = drv.mem_alloc(h_x.nbytes)
24+
d_y = drv.mem_alloc(h_y.nbytes)
25+
d_z = drv.mem_alloc(h_z.nbytes)
26+
drv.memcpy_htod(d_x, h_x)
27+
drv.memcpy_htod(d_y, h_y)
28+
add(d_x, d_y, d_z, grid=(N//128, 1), block=(128,1,1))
29+
drv.memcpy_dtoh(h_z, d_z)
3030
print('No errors' if (abs(h_z-c)<EPSILON).all() else 'Has errors')

0 commit comments

Comments
 (0)