diff --git a/advanced/algorithms/username/gpu_test/1.json b/advanced/algorithms/username/gpu_test/1.json new file mode 100644 index 0000000000000000000000000000000000000000..3744b518446e266828a5579f9d7ba3e9f634df1b --- /dev/null +++ b/advanced/algorithms/username/gpu_test/1.json @@ -0,0 +1,30 @@ +{ + "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" +} diff --git a/advanced/algorithms/username/gpu_test/1.py b/advanced/algorithms/username/gpu_test/1.py new file mode 100644 index 0000000000000000000000000000000000000000..149dc2e569813d4cf0567885cb81e9da9b381418 --- /dev/null +++ b/advanced/algorithms/username/gpu_test/1.py @@ -0,0 +1,61 @@ +############################################################################### +# # +# 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 diff --git a/advanced/algorithms/username/gpu_test/1.rst b/advanced/algorithms/username/gpu_test/1.rst new file mode 100644 index 0000000000000000000000000000000000000000..3d94c664f22939a845fd14ae04420d9c367d589e --- /dev/null +++ b/advanced/algorithms/username/gpu_test/1.rst @@ -0,0 +1,22 @@ +.. 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 diff --git a/test/algorithms/username/integers_add_torch_autonomous/1.json b/test/algorithms/username/integers_add_torch_autonomous/1.json index 09b49e7f1d20b1fd24480cdb37136c06a45ce9fe..adec321a34a22cdf735a9c1856cab52b73f066c3 100644 --- a/test/algorithms/username/integers_add_torch_autonomous/1.json +++ b/test/algorithms/username/integers_add_torch_autonomous/1.json @@ -20,7 +20,7 @@ ], "parameters": { "offset": { - "default": "1", + "default": 1, "type": "int32" } }, diff --git a/test/algorithms/username/integers_add_torch_legacy/1.json b/test/algorithms/username/integers_add_torch_legacy/1.json index e59a0ec1632963019b22843dfea528b24a86cde5..578d04b6e07d6357ff0af28745baa5b3bad00e12 100644 --- a/test/algorithms/username/integers_add_torch_legacy/1.json +++ b/test/algorithms/username/integers_add_torch_legacy/1.json @@ -18,7 +18,7 @@ ], "parameters": { "offset": { - "default": "1", + "default": 1, "type": "int32" } }, diff --git a/test/algorithms/username/integers_add_torch_sequential/1.json b/test/algorithms/username/integers_add_torch_sequential/1.json index 74bca6f7cd40b562a7170cdd16a93a969a8d9c81..67a0153ae07b3a30d27f802f150b9b6b2bb433c3 100644 --- a/test/algorithms/username/integers_add_torch_sequential/1.json +++ b/test/algorithms/username/integers_add_torch_sequential/1.json @@ -20,7 +20,7 @@ ], "parameters": { "offset": { - "default": "1", + "default": 1, "type": "int32" }, "sync": {