Skip to content
Snippets Groups Projects
Commit 98c0c7a3 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[advanced][algorithms] Add basic GPU using algorithm

parent 6c79c21f
No related branches found
No related tags found
1 merge request!20GPU sample
{
"type": "sequential",
"groups": [
{
"outputs": {
"scores": {
"type": "{{ user.username }}/probe_scores/1"
}
},
"inputs": {
"client_id": {
"type": "{{ system_user.username }}/uint64/1"
}
},
"name": "main"
}
],
"parameters": {
"offset": {
"type": "uint32",
"default": 10,
"description": "Offset"
}
},
"schema_version": 2,
"api_version": 2,
"description": "",
"splittable": false,
"language": "python"
}
###############################################################################
# #
# Copyright (c) 2019 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.examples module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import numpy
import torch
class Algorithm:
def __init__(self):
self.offset = 1
def setup(self, parameters):
self.offset = numpy.asscalar(parameters['offset'])
return torch.cuda.is_available()
def process(self, inputs, data_loaders, outputs):
client_id = inputs['client_id'].data.value
x = torch.FloatTensor(1, 1).fill_(numpy.asscalar(client_id)).cuda()
y = torch.FloatTensor(1, 1).fill_(self.offset).cuda()
z = x + y
score = z.cpu().numpy().astype(numpy.int32)[0][0]
scores = [
{
'template_identity': client_id,
'score': score if client_id % 2 else -score
},
{
'template_identity': 0,
'score': -score if client_id % 2 else score
}
]
outputs['scores'].write({
'client_identity': client_id,
'scores': scores
})
return True
.. Copyright (c) 2019 Idiap Research Institute, http://www.idiap.ch/ ..
.. Contact: beat.support@idiap.ch ..
.. ..
.. This file is part of the beat.examples module of the BEAT platform. ..
.. ..
.. Commercial License Usage ..
.. Licensees holding valid commercial BEAT licenses may use this file in ..
.. accordance with the terms contained in a written agreement between you ..
.. and Idiap. For further information contact tto@idiap.ch ..
.. ..
.. Alternatively, this file may be used under the terms of the GNU Affero ..
.. Public License version 3 as published by the Free Software and appearing ..
.. in the file LICENSE.AGPL included in the packaging of this file. ..
.. The BEAT platform is distributed in the hope that it will be useful, but ..
.. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ..
.. or FITNESS FOR A PARTICULAR PURPOSE. ..
.. ..
.. You should have received a copy of the GNU Affero Public License along ..
.. with the BEAT platform. If not, see http://www.gnu.org/licenses/. ..
Minimal algorithm validating GPU setup.
\ No newline at end of file
......@@ -20,7 +20,7 @@
],
"parameters": {
"offset": {
"default": "1",
"default": 1,
"type": "int32"
}
},
......
......@@ -18,7 +18,7 @@
],
"parameters": {
"offset": {
"default": "1",
"default": 1,
"type": "int32"
}
},
......
......@@ -20,7 +20,7 @@
],
"parameters": {
"offset": {
"default": "1",
"default": 1,
"type": "int32"
},
"sync": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment