Skip to content

Commit d36feeb

Browse files
authored
Merge pull request pocl#1702 from Yashvardhan-A/Android-discovery-support
Android: remote device addition
2 parents 063ebcd + c865893 commit d36feeb

File tree

7 files changed

+76
-5
lines changed

7 files changed

+76
-5
lines changed

CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,11 @@ else()
318318
endif()
319319
option(ENABLE_LLVM_PLATFORM_SUPPORT "Enable platform support using C++ STL and LLVM's Support library" ${DEFAULT_LLVM_PLATFORM_SUPPORT})
320320

321-
option(ENABLE_REMOTE_DISCOVERY_AVAHI "Enable remote disocvery in remote device for linux using avahi" OFF)
321+
option(ENABLE_REMOTE_DISCOVERY_AVAHI "Enable remote discovery in remote device for linux using avahi" OFF)
322322

323-
option(ENABLE_REMOTE_DISCOVERY_DHT "Enable remote disocvery in remote device for linux using DHT" OFF)
323+
option(ENABLE_REMOTE_DISCOVERY_DHT "Enable remote discovery in remote device for linux using DHT" OFF)
324+
325+
option(ENABLE_REMOTE_DISCOVERY_ANDROID "Enable remote discovery support in remote device for Android" OFF)
324326

325327
option(ENABLE_REMOTE_ADVERTISEMENT_AVAHI "Enable remote server advertisement using avahi" OFF)
326328

config.h.in.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757

5858
#cmakedefine ENABLE_REMOTE_DISCOVERY_DHT
5959

60+
#cmakedefine ENABLE_REMOTE_DISCOVERY_ANDROID
61+
6062
#cmakedefine ENABLE_REMOTE_ADVERTISEMENT_AVAHI
6163

6264
#cmakedefine ENABLE_REMOTE_ADVERTISEMENT_DHT

doc/sphinx/source/remote.rst

+4
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ Remote Client:
423423

424424
* ``-DENABLE_REMOTE_DISCOVERY_DHT``: Enable DHT-based discovery.
425425

426+
* ``-DENABLE_REMOTE_DISCOVERY_ANDROID``: Enables discovery for Android. The helper
427+
function ``pocl_remote_discovery_add_server()`` in include/pocl_remote.h can be
428+
used to dynamically add remote servers and its devices through the remote driver.
429+
426430
Remote Server:
427431

428432
* ``-DENABLE_REMOTE_ADVERTISEMENT_AVAHI``: Enable mDNS advertisement via Avahi.

include/pocl_remote.h

+34
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#ifndef POCL_REMOTE_SHARED_H
2525
#define POCL_REMOTE_SHARED_H
2626

27+
#if defined(ENABLE_REMOTE_DISCOVERY_ANDROID)
28+
#include <CL/cl_platform.h>
29+
#endif
30+
2731
#define DEFAULT_POCL_REMOTE_PORT 10998
2832

2933
#define MAX_REMOTE_BUILDPROGRAM_SIZE (16 << 20)
@@ -32,4 +36,34 @@
3236

3337
#define MAX_REMOTE_PARAM_LENGTH 256
3438

39+
#if defined(ENABLE_REMOTE_DISCOVERY_ANDROID)
40+
#ifdef __cplusplus
41+
extern "C"
42+
{
43+
#endif
44+
45+
/**
46+
* Helper function used to dynamically add a remote server and its devices.
47+
* It is currently only used by android where the network discovery is
48+
* performed using android network libraries and the discovered servers are
49+
* added using this function. The function is implemented in the remote
50+
* driver in network_discovery.c.
51+
*
52+
* \param id [in] Unique ID with which server advertises itself.
53+
* \param domain [in] Domain name in which the server was found.
54+
* \param server_key [in] Combination of "IP:port"
55+
* \param type [in] Type of the discovered service. Eg type: "_pocl._tcp"
56+
* \param device_count [in] Number of devices in the remote server.
57+
*/
58+
void pocl_remote_discovery_add_server (const char *id,
59+
const char *domain,
60+
const char *server_key,
61+
const char *type,
62+
cl_uint device_count);
63+
64+
#ifdef __cplusplus
65+
}
66+
#endif
67+
#endif
68+
3569
#endif

lib/CL/devices/remote/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,9 @@ if(ENABLE_REMOTE_DISCOVERY_DHT)
4545
list(APPEND POCL_REMOTE_CLIENT_SOURCES network_discovery.c network_discovery.h)
4646
endif()
4747

48+
if(ENABLE_REMOTE_DISCOVERY_ANDROID)
49+
list(APPEND POCL_REMOTE_CLIENT_SOURCES network_discovery.c network_discovery.h)
50+
endif()
51+
4852
add_pocl_device_library("pocl-devices-remote" ${POCL_REMOTE_CLIENT_SOURCES})
4953
target_link_libraries("pocl-devices-remote" PRIVATE ${LIBS})

lib/CL/devices/remote/network_discovery.c

+22
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "network_discovery.h"
3232
#include "pocl_cl.h"
3333
#include "pocl_debug.h"
34+
#include "pocl_remote.h"
3435
#include "pocl_runtime_config.h"
3536
#include "pocl_threads.h"
3637
#include "uthash.h"
@@ -657,6 +658,27 @@ init_dht_discovery ()
657658

658659
/*****************************************************************************/
659660

661+
#if defined(ENABLE_REMOTE_DISCOVERY_ANDROID)
662+
663+
/**
664+
* Helper function used by android to add servers through the remote driver.
665+
*
666+
* The function declaration is in include/pocl_remote.h.
667+
*/
668+
void
669+
pocl_remote_discovery_add_server (const char *id,
670+
const char *domain,
671+
const char *server_key,
672+
const char *type,
673+
cl_uint device_count)
674+
{
675+
handle_server_discovery (id, domain, server_key, type, device_count);
676+
}
677+
678+
#endif
679+
680+
/*****************************************************************************/
681+
660682
/**
661683
* Function called by the remote driver to initialize network discovery
662684
* methods.

lib/CL/devices/remote/remote.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
#include "messages.h"
5555

5656
#if defined(ENABLE_REMOTE_DISCOVERY_AVAHI) \
57-
|| defined(ENABLE_REMOTE_DISCOVERY_DHT)
57+
|| defined(ENABLE_REMOTE_DISCOVERY_DHT) \
58+
|| defined(ENABLE_REMOTE_DISCOVERY_ANDROID)
5859
#include "network_discovery.h"
5960
#endif
6061

@@ -380,7 +381,8 @@ pocl_remote_init_device_ops (struct pocl_device_ops *ops)
380381
ops->free_sampler = pocl_remote_free_sampler;
381382

382383
#if defined(ENABLE_REMOTE_DISCOVERY_AVAHI) \
383-
|| defined(ENABLE_REMOTE_DISCOVERY_DHT)
384+
|| defined(ENABLE_REMOTE_DISCOVERY_DHT) \
385+
|| defined(ENABLE_REMOTE_DISCOVERY_ANDROID)
384386
ops->init_discovery = pocl_remote_init_device_discovery;
385387
#endif
386388
}
@@ -640,7 +642,8 @@ pocl_remote_init (unsigned j, cl_device_id device, const char *parameters)
640642
}
641643

642644
#if defined(ENABLE_REMOTE_DISCOVERY_AVAHI) \
643-
|| defined(ENABLE_REMOTE_DISCOVERY_DHT)
645+
|| defined(ENABLE_REMOTE_DISCOVERY_DHT) \
646+
|| defined(ENABLE_REMOTE_DISCOVERY_ANDROID)
644647
cl_int
645648
pocl_remote_init_device_discovery (
646649
cl_int (*add_discovered_device) (const char *, unsigned),

0 commit comments

Comments
 (0)