RemoteAccelerator.hpp 3.2 KB
Newer Older
Mccaskey, Alex's avatar
Mccaskey, Alex committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*******************************************************************************
 * Copyright (c) 2017 UT-Battelle, LLC.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v1.0 which accompanies this
 * distribution. The Eclipse Public License is available at
 * http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License
 * is available at https://eclipse.org/org/documents/edl-v10.php
 *
 * Contributors:
 *   Alexander J. McCaskey - initial API and implementation
 *******************************************************************************/
#ifndef XACC_ACCELERATOR_REMOTE_REMOTEACCELERATOR_HPP_
#define XACC_ACCELERATOR_REMOTE_REMOTEACCELERATOR_HPP_

#include "Accelerator.hpp"
17
18
#include "XACC.hpp"

Mccaskey, Alex's avatar
Mccaskey, Alex committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>

using namespace utility;
using namespace web;
using namespace web::http;
using namespace web::http::client;
using namespace concurrency::streams;

namespace xacc {

class RestClient {

public:

	virtual const std::string post(const std::string& remoteUrl,
			const std::string& path, const std::string& postStr,
			std::map<std::string, std::string> headers = std::map<std::string,
37
					std::string> { });
Mccaskey, Alex's avatar
Mccaskey, Alex committed
38
39

	virtual const std::string get(const std::string& remoteUrl,
40
41
			const std::string& path,
			std::map<std::string, std::string> headers = std::map<std::string,
42
					std::string> { });
Mccaskey, Alex's avatar
Mccaskey, Alex committed
43
44
45

	virtual ~RestClient() {}

46

Mccaskey, Alex's avatar
Mccaskey, Alex committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
};

class RemoteAccelerator : public Accelerator {

public:

	RemoteAccelerator() : Accelerator(), restClient(std::make_shared<RestClient>()) {}

	RemoteAccelerator(std::shared_ptr<RestClient> client) : restClient(client) {}


	/**
	 * Execute the provided XACC IR Function on the provided AcceleratorBuffer.
	 *
	 * @param buffer The buffer of bits this Accelerator should operate on.
	 * @param function The kernel to execute.
	 */
	virtual void execute(std::shared_ptr<AcceleratorBuffer> buffer,
65
				const std::shared_ptr<Function> function);
Mccaskey, Alex's avatar
Mccaskey, Alex committed
66
67
68
69
70
71
72
73
74
75
76
77
78

	/**
	 * Execute a set of kernels with one remote call. Return
	 * a list of AcceleratorBuffers that provide a new view
	 * of the given one AcceleratorBuffer. The ith AcceleratorBuffer
	 * contains the results of the ith kernel execution.
	 *
	 * @param buffer The AcceleratorBuffer to execute on
	 * @param functions The list of IR Functions to execute
	 * @return tempBuffers The list of new AcceleratorBuffers
	 */
	virtual std::vector<std::shared_ptr<AcceleratorBuffer>> execute(
			std::shared_ptr<AcceleratorBuffer> buffer,
79
			const std::vector<std::shared_ptr<Function>> functions);
80
81
82
83
84

	virtual bool isRemote() {
		return true;
	}

Mccaskey, Alex's avatar
Mccaskey, Alex committed
85
86
87
88
89
90
91
92
protected:

	std::shared_ptr<RestClient> restClient;

	std::string postPath;

	std::string remoteUrl;

93
94
	std::map<std::string, std::string> headers;

Mccaskey, Alex's avatar
Mccaskey, Alex committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
	/**
	 * take ir, generate json post string
	 */
	virtual const std::string processInput(std::shared_ptr<AcceleratorBuffer> buffer,
			std::vector<std::shared_ptr<Function>> functions) = 0;

	/**
	 * take response and create
	 */
	virtual std::vector<std::shared_ptr<AcceleratorBuffer>> processResponse(
			std::shared_ptr<AcceleratorBuffer> buffer,
			const std::string& response) = 0;

};

}

#endif