Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test gpu #1

Open
wants to merge 84 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
160b086
tests: Add test gpu.
rhodrin Jan 10, 2020
cb14bda
Fix indentation error.
rhodrin Jan 10, 2020
458199f
Fix assert.
Jan 10, 2020
f41b4d5
Tidying.
rhodrin Jan 10, 2020
dca0455
Fix typo.
Jan 10, 2020
e67e06a
tests: Add iso-acoustic gpu test.
rhodrin Jan 10, 2020
d3660c4
tests: Modify iso acoustic gpu test.
rhodrin Jan 10, 2020
1d5aba0
tests: gpu test modification.
rhodrin Jan 10, 2020
9934a12
workflows: Add gpu workflow
rhodrin Jan 20, 2020
6d3245b
actions: Add gpu action.
rhodrin Jan 21, 2020
e9a7a73
actions: Update gpu action.
rhodrin Feb 5, 2020
9ca6aa1
actions: Typo.
rhodrin Feb 5, 2020
f420a2c
actions: powershell -> pwsh.
rhodrin Feb 5, 2020
f70e2d7
Trigger build.
rhodrin Feb 7, 2020
79a0198
Flake8.
rhodrin Feb 7, 2020
29463a9
actions: Test config.
rhodrin Feb 7, 2020
335bbf4
Test.
rhodrin Feb 7, 2020
56f6613
Trigger workflow.
rhodrin Feb 7, 2020
6c56b54
Test.
rhodrin Feb 7, 2020
aec59f0
.
rhodrin Feb 7, 2020
d5f9b4f
.
rhodrin Feb 7, 2020
1d5b73c
1451
rhodrin Feb 7, 2020
f579f28
.
rhodrin Feb 7, 2020
4c52e39
1611
rhodrin Feb 7, 2020
df175bb
1624
rhodrin Feb 7, 2020
4f04020
1634
rhodrin Feb 7, 2020
20d9d4a
1724
rhodrin Feb 7, 2020
b8f30f8
1734
rhodrin Feb 7, 2020
b300091
1740
rhodrin Feb 7, 2020
a687cda
1752
rhodrin Feb 7, 2020
80204a0
1803
rhodrin Feb 7, 2020
1cdc064
1810
rhodrin Feb 7, 2020
a31fb38
1816
rhodrin Feb 7, 2020
b39450f
1837
rhodrin Feb 7, 2020
fd46d7b
workflows: Set correct image for GPU testing.
rhodrin Feb 10, 2020
3bfbed9
Test. Remove.
rhodrin Feb 10, 2020
44c53e2
force build.
rhodrin Feb 10, 2020
80da0a6
test.
rhodrin Feb 10, 2020
81ffdfc
.
rhodrin Feb 10, 2020
80ec50b
force build.
rhodrin Feb 10, 2020
1549613
.
rhodrin Feb 10, 2020
ce196b9
.
rhodrin Feb 10, 2020
e3a1809
.
rhodrin Feb 10, 2020
ee8d7a8
.
rhodrin Feb 10, 2020
c75e74c
.
rhodrin Feb 10, 2020
2c205fa
.
rhodrin Feb 10, 2020
f7d32d4
.
rhodrin Feb 10, 2020
53f7dec
.
rhodrin Feb 10, 2020
40f37d5
.
rhodrin Feb 10, 2020
68e9b2e
.
rhodrin Feb 18, 2020
5b41541
.
rhodrin Feb 18, 2020
71c1784
.
rhodrin Feb 18, 2020
98b701a
.
rhodrin Feb 18, 2020
b053858
.
rhodrin Feb 18, 2020
9a0c8ee
.
rhodrin Feb 18, 2020
2645b12
.
rhodrin Feb 18, 2020
fa5cf13
.
rhodrin Feb 18, 2020
939eccb
.
rhodrin Feb 18, 2020
e97ce0a
.
rhodrin Feb 18, 2020
304da7f
.
rhodrin Feb 18, 2020
99b2030
.
rhodrin Feb 18, 2020
8d736b4
.
rhodrin Feb 18, 2020
968d6f7
.
rhodrin Feb 18, 2020
58f988b
.
rhodrin Feb 18, 2020
d5afab6
.
rhodrin Feb 18, 2020
a62874d
.
rhodrin Feb 18, 2020
5981b43
.
rhodrin Feb 18, 2020
c8d46eb
.
rhodrin Feb 18, 2020
3c8a2d3
.
rhodrin Feb 18, 2020
59ebd13
.
rhodrin Feb 18, 2020
464cde3
.
rhodrin Feb 18, 2020
38598a3
.
rhodrin Feb 18, 2020
6f5259a
.
rhodrin Feb 18, 2020
c991dc6
.
rhodrin Feb 18, 2020
f12fbf5
.
rhodrin Feb 18, 2020
2651ac0
.
rhodrin Feb 18, 2020
a01f105
.
rhodrin Feb 18, 2020
4d9ef9b
.
rhodrin Feb 18, 2020
eebe42f
.
rhodrin Feb 18, 2020
414a442
.
rhodrin Feb 19, 2020
a40b866
.
rhodrin Feb 19, 2020
fa31aa1
.
rhodrin Feb 19, 2020
83eacd5
.
rhodrin Feb 19, 2020
179b305
.
rhodrin Feb 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/pytest-gpu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Adapted from https://github.com/weeyin83/vm-actions
name: Deploy VM on Azure and run GPU tests

env:
OUTPUT_PATH: ${{ github.workspace }}

on: [push]

jobs:

# Deploy VM in Azure
DeployVM:
runs-on: ubuntu-latest

steps:
# checkout code from repo
- name: checkout repo
uses: actions/checkout@v1

- name: look for ps1 file
run: |
ls '${{ env.OUTPUT_PATH }}/PSA'
- name: deploy VM
env:
RESOURCE_GROUP: RhodriGpu
RESOURCE_GROUP_REGION: uksouth
SERVER_NAME: testgpu
run: >
pwsh -command "& '${{ env.OUTPUT_PATH }}\PSA\deployVM.ps1'"
-servicePrincipal ${{ secrets.SERVICE_PRINCIPAL_APPID }}
-servicePrincipalSecret ${{ secrets.SERVICE_PRINCIPAL_SECRET }}
-servicePrincipalTenantId ${{ secrets.SERVICE_PRINCIPAL_TENANTID }}
-azureSubscriptionName ${{ secrets.AZURE_SUBSCRIPTION_ID }}
-resourceGroupName $RESOURCE_GROUP
-resourceGroupNameRegion $RESOURCE_GROUP_REGION
-serverName $SERVER_NAME
-adminLogin ${{ secrets.ADMIN_LOGIN }}
-adminPassword ${{ secrets.ADMIN_PASSWORD }}
- name: set host
run: echo ::set-output name=action_host::$(az vm show -d -g RhodriGpu -n testgpu --query publicIps -o tsv)
id: host
- name: executing remote ssh commands test
uses: fifsky/ssh-action@master
with:
command: |
export PATH=~/programs/install/bin:$PATH
export LD_LIBRARY_PATH=~/programs/install/lib:$LD_LIBRARY_PATH
source ~/anaconda3/etc/profile.d/conda.sh
conda activate devito
cd ~/programs/devito
DEVITO_ARCH=clang DEVITO_PLATFORM=nvidiaX py.test -s -x --cov devito tests/test_gpu.py
host: ${{ steps.host.outputs.action_host }}
user: ${{ secrets.ADMIN_LOGIN }}
pass: ${{ secrets.ADMIN_PASSWORD }}
93 changes: 93 additions & 0 deletions PSA/deployVM.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Adapted from https://github.com/weeyin83/vm-actions
# Provision a VM within Azure (test)
#
[CmdletBinding()]
param(
[Parameter(Mandatory = $True)]
[string]
$servicePrincipal,

[Parameter(Mandatory = $True)]
[string]
$servicePrincipalSecret,

[Parameter(Mandatory = $True)]
[string]
$servicePrincipalTenantId,

[Parameter(Mandatory = $True)]
[string]
$azureSubscriptionName,

[Parameter(Mandatory = $True)]
[string]
$resourceGroupName,

[Parameter(Mandatory = $True)]
[string]
$resourceGroupNameRegion,

[Parameter(Mandatory = $True)]
[string]
$serverName,

[Parameter(Mandatory = $True)]
[string]
$adminLogin,

[Parameter(Mandatory = $True)]
[String]
$adminPassword
)


#region Login
# This logs into Azure with a Service Principal Account
#
Write-Output "Logging in to Azure with a service principal..."
az login `
--service-principal `
--username $servicePrincipal `
--password $servicePrincipalSecret `
--tenant $servicePrincipalTenantId
Write-Output "Done"
Write-Output ""
#endregion

#region Subscription
#This sets the subscription the resources will be created in

Write-Output "Setting default azure subscription..."
az account set `
--subscription $azureSubscriptionName
Write-Output "Done"
Write-Output ""
#endregion

#region Create Resource Group
# This creates the resource group used to house the VM
Write-Output "Creating resource group $resourceGroupName in region $resourceGroupNameRegion..."
az group create `
--name $resourceGroupName `
--location $resourceGroupNameRegion
Write-Output "Done creating resource group"
Write-Output ""
#endregion

#region Create VM
# Create a VM in the resource group
Write-Output "Creating VM..."
try {
az vm create `
--resource-group $resourceGroupName `
--name $serverName `
--image RhodriGpuVM-image-20200210110731 `
--admin-username $adminLogin `
--admin-password $adminPassword
}
catch {
Write-Output "VM already exists"
}
Write-Output "Done creating VM"
Write-Output ""
#endregion
2 changes: 1 addition & 1 deletion devito/archinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def __init__(self, name, cores_logical=1, cores_physical=1, isa='cpp'):
POWER9 = Power('power9')

# Devices
NVIDIAX = Device('nvidiax')
NVIDIAX = Device('nvidiaX')


platform_registry = {
Expand Down
50 changes: 1 addition & 49 deletions tests/test_dle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from conftest import skipif
from devito import (Grid, Function, TimeFunction, SparseTimeFunction, SubDimension,
Eq, Operator, switchconfig)
Eq, Operator)
from devito.exceptions import InvalidArgument
from devito.ir.iet import Call, Iteration, Conditional, FindNodes, retrieve_iteration_tree
from devito.passes import BlockDimension, NThreads, NThreadsNonaffine
Expand Down Expand Up @@ -508,51 +508,3 @@ def test_multiple_subnests(self):
assert trees[1][2].pragmas[0].value == ('omp parallel for collapse(1) '
'schedule(dynamic,1) '
'num_threads(nthreads_nested)')


class TestOffloading(object):

@switchconfig(platform='nvidiaX')
def test_basic(self):
grid = Grid(shape=(3, 3, 3))

u = TimeFunction(name='u', grid=grid)

op = Operator(Eq(u.forward, u + 1), dle=('advanced', {'openmp': True}))

trees = retrieve_iteration_tree(op)
assert len(trees) == 1

assert trees[0][1].pragmas[0].value ==\
'omp target teams distribute parallel for collapse(3)'
assert op.body[1].header[1].value ==\
('omp target enter data map(to: u[0:u_vec->size[0]]'
'[0:u_vec->size[1]][0:u_vec->size[2]][0:u_vec->size[3]])')
assert op.body[1].footer[0].value ==\
('omp target exit data map(from: u[0:u_vec->size[0]]'
'[0:u_vec->size[1]][0:u_vec->size[2]][0:u_vec->size[3]])')

@switchconfig(platform='nvidiaX')
def test_multiple_eqns(self):
grid = Grid(shape=(3, 3, 3))

u = TimeFunction(name='u', grid=grid)
v = TimeFunction(name='v', grid=grid)

op = Operator([Eq(u.forward, u + v + 1), Eq(v.forward, u + v + 4)],
dle=('advanced', {'openmp': True}))

trees = retrieve_iteration_tree(op)
assert len(trees) == 1

assert trees[0][1].pragmas[0].value ==\
'omp target teams distribute parallel for collapse(3)'
for i, f in enumerate([u, v]):
assert op.body[2].header[2 + i].value ==\
('omp target enter data map(to: %(n)s[0:%(n)s_vec->size[0]]'
'[0:%(n)s_vec->size[1]][0:%(n)s_vec->size[2]][0:%(n)s_vec->size[3]])' %
{'n': f.name})
assert op.body[2].footer[i].value ==\
('omp target exit data map(from: %(n)s[0:%(n)s_vec->size[0]]'
'[0:%(n)s_vec->size[1]][0:%(n)s_vec->size[2]][0:%(n)s_vec->size[3]])' %
{'n': f.name})
118 changes: 118 additions & 0 deletions tests/test_gpu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import numpy as np
import pytest

from conftest import skipif
from devito import Grid, TimeFunction, Eq, Operator, switchconfig
from devito.ir.iet import retrieve_iteration_tree

pytestmark = skipif(['yask', 'ops'])


class TestOffloading(object):

@switchconfig(platform='nvidiaX')
def test_basic(self):
grid = Grid(shape=(3, 3, 3))

u = TimeFunction(name='u', grid=grid)

op = Operator(Eq(u.forward, u + 1), dle=('advanced', {'openmp': True}))

trees = retrieve_iteration_tree(op)
assert len(trees) == 1

assert trees[0][1].pragmas[0].value ==\
'omp target teams distribute parallel for collapse(3)'
assert op.body[1].header[1].value ==\
('omp target enter data map(to: u[0:u_vec->size[0]]'
'[0:u_vec->size[1]][0:u_vec->size[2]][0:u_vec->size[3]])')
assert op.body[1].footer[0].value ==\
('omp target exit data map(from: u[0:u_vec->size[0]]'
'[0:u_vec->size[1]][0:u_vec->size[2]][0:u_vec->size[3]])')

@switchconfig(platform='nvidiaX')
def test_multiple_eqns(self):
grid = Grid(shape=(3, 3, 3))

u = TimeFunction(name='u', grid=grid)
v = TimeFunction(name='v', grid=grid)

op = Operator([Eq(u.forward, u + v + 1), Eq(v.forward, u + v + 4)],
dle=('advanced', {'openmp': True}))

trees = retrieve_iteration_tree(op)
assert len(trees) == 1

assert trees[0][1].pragmas[0].value ==\
'omp target teams distribute parallel for collapse(3)'
for i, f in enumerate([u, v]):
assert op.body[2].header[2 + i].value ==\
('omp target enter data map(to: %(n)s[0:%(n)s_vec->size[0]]'
'[0:%(n)s_vec->size[1]][0:%(n)s_vec->size[2]][0:%(n)s_vec->size[3]])' %
{'n': f.name})
assert op.body[2].footer[i].value ==\
('omp target exit data map(from: %(n)s[0:%(n)s_vec->size[0]]'
'[0:%(n)s_vec->size[1]][0:%(n)s_vec->size[2]][0:%(n)s_vec->size[3]])' %
{'n': f.name})

@switchconfig(platform='nvidiaX')
def test_op_apply(self):
grid = Grid(shape=(3, 3, 3))

u = TimeFunction(name='u', grid=grid, dtype=np.int32)

op = Operator(Eq(u.forward, u + 1), dle=('advanced', {'openmp': True}))

time_steps = 1000
op.apply(time_M=time_steps)

assert np.all(np.array(u.data[0, :, :, :]) == time_steps)

@pytest.mark.xfail
@switchconfig(platform='nvidiaX')
def test_iso_ac(self):
from examples.seismic import TimeAxis, RickerSource, Receiver
from devito import Function, solve, norm

shape = (101, 101)
extent = (1000, 1000)
origin = (0., 0.)

v = np.empty(shape, dtype=np.float32)
v[:, :51] = 1.5
v[:, 51:] = 2.5

grid = Grid(shape=shape, extent=extent, origin=origin)

t0 = 0.
tn = 1000.
dt = 1.6
time_range = TimeAxis(start=t0, stop=tn, step=dt)

f0 = 0.010
src = RickerSource(name='src', grid=grid, f0=f0,
npoint=1, time_range=time_range)

domain_size = np.array(extent)

src.coordinates.data[0, :] = domain_size*.5
src.coordinates.data[0, -1] = 20.

rec = Receiver(name='rec', grid=grid, npoint=101, time_range=time_range)
rec.coordinates.data[:, 0] = np.linspace(0, domain_size[0], num=101)
rec.coordinates.data[:, 1] = 20.

u = TimeFunction(name="u", grid=grid, time_order=2, space_order=2)
m = Function(name='m', grid=grid)
m.data[:] = 1./(v*v)

pde = m * u.dt2 - u.laplace
stencil = Eq(u.forward, solve(pde, u.forward))

src_term = src.inject(field=u.forward, expr=src * dt**2 / m)
rec_term = rec.interpolate(expr=u.forward)

op = Operator([stencil] + src_term + rec_term, dle=('advanced', {'openmp': True}))
op(time=time_range.num-1, dt=dt)

assert np.isclose(norm(rec), 490.5477, atol=1e-3, rtol=0)