def test_amountOfComputation(): X = np.random.randn(1, 1, 4, 4) W = np.random.randn(1, 1, 2, 2) hparam = {"pad": 0, "stride": 1} obj = Offload(1, 1, 1, X, W, hparam) assert obj.amountOfComputation() == 9 * 7
def test_vecShape(): X = np.random.randn(1, 2, 4, 4) W = np.random.randn(1, 2, 2, 2) hparam = {"pad": 0, "stride": 1} obj = Offload(1, 1, 1, X, W, hparam) assert obj.vecShape() == (9, 8)
def test_outshape(): """ X-numpy array numpy array (m,n_C, n_H, n_W) k-kernel (n_C, n_C_prev, f, f) out-(m,c,nh,nw) """ X = np.random.randn(10, 4, 5, 7) W = np.random.randn(8, 4, 3, 3) hparam = {"pad": 1, "stride": 2} obj = Offload(1, 1, 1, X, W, hparam) assert obj.outShape() == (10, 8, 3, 4)
def compute(self, n_speed, s_speed, msize, thershold, bandwidth): """ n_speed-node CPU speed s_speed-server CPU speed msize-node memory size thershold-maximum memory limit """ X = self.image for index, layer in enumerate(self.CNN): #layer dictonary {type,kernel,bias,hparams} #offloading decisions kernel = kernels[layer["kernel"]] hparam = layer["hparams"] if (layer["l_type"] == "conv"): #n_speed,s_speed,msize,X,kernel,hparam,bandwidth_up,bandwidth_down off_dec = Offload(n_speed, s_speed, msize, X, kernel, hparam, bandwidth, bandwidth) offDec = off_dec.checkOffload(thershold) else: #pooling layer memory usage offDec = self.poolingMem(X, hparam) if X.shape[2] < 50: pos = 0 if layer[l_type] == "conv": pos = (0, kernel.shape[3]) else: pos = (0, X.shape[2]) X = self.layerResult(layer, X, pos) elif (offDec): #get the result form the server conv_dict = {"data": X, "index": index} c = client(conv_dict, self.edge["ip"], self.edge["port"]) c.send() X = c.receive_array() else: X = self.thread_Compute(X, layer) #activation function and bais apply for conv if layer[l_type] == "conv": X += kernels[layer["bias"]] X = ActivationFunc(X, layer["act"])