cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
custom.py
Go to the documentation of this file.
1 # *****************************************************************************
2 # * cloudFPGA
3 # * Copyright 2016 -- 2022 IBM Corporation
4 # * Licensed under the Apache License, Version 2.0 (the "License");
5 # * you may not use this file except in compliance with the License.
6 # * You may obtain a copy of the License at
7 # *
8 # * http://www.apache.org/licenses/LICENSE-2.0
9 # *
10 # * Unless required by applicable law or agreed to in writing, software
11 # * distributed under the License is distributed on an "AS IS" BASIS,
12 # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # * See the License for the specific language governing permissions and
14 # * limitations under the License.
15 # *----------------------------------------------------------------------------
16 
17 
24 
25 import sys
26 import os
27 import numpy as np
28 import socket
29 import logging
30 
31 # Setting SO_RCVBUF
32 # Sets or gets the maximum socket receive buffer in bytes. The kernel doubles
33 # this value (to allow space for bookkeeping overhead) when it is set using
34 # setsockopt(2), and this doubled value is returned by getsockopt(2).
35 # The default value is set by the /proc/sys/net/core/rmem_default file, and
36 # the maximum allowed value is set by the /proc/sys/net/core/rmem_max file.
37 # The minimum (doubled) value for this option is 256.
38 recvBufSize = 0x1000000
39 real_buffer_size = 0
40 
41 def uppercase(input_array, total_size, fpga_ip, fpga_port, debug_level):
42  logging.basicConfig(level=debug_level)
43  bytesToSend = input_array.tostring()
44  # Create a UDP socket at client side
45  UDPClientSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
46  previous_buffer_size = UDPClientSocket.getsockopt(socket.SOL_SOCKET,socket.SO_RCVBUF)
47  UDPClientSocket.setsockopt(socket.SOL_SOCKET,socket.SO_RCVBUF, recvBufSize)
48  real_buffer_size = UDPClientSocket.getsockopt(socket.SOL_SOCKET,socket.SO_RCVBUF)
49  if(real_buffer_size/2 != recvBufSize):
50  logging.warning("set SO_RCVBUF failed! got only: " +str(real_buffer_size/2) + "; trying to continue...")
51  BUFF_SIZE = 1024#65536
52  serverAddressPort = (fpga_ip, fpga_port)
53  cnt = 0;
54  while True:
55  logging.debug("Sending bytes: " + str(cnt*BUFF_SIZE) + " : " + str((cnt+1)*BUFF_SIZE-1))
56  UDPClientSocket.sendto(bytesToSend[cnt*BUFF_SIZE:(cnt+1)*BUFF_SIZE], serverAddressPort)
57  if ((cnt+1)*BUFF_SIZE >= total_size):
58  logging.debug("INFO: Reached size to sent")
59  break;
60  else:
61  cnt = cnt + 1
62  cnt = 0;
63  output_array = np.zeros((total_size,), dtype=input_array.dtype)
64  while True:
65  logging.debug("Receiving bytes: " + str(cnt*BUFF_SIZE) + " : " + str((cnt+1)*BUFF_SIZE-1))
66  msgFromServer = UDPClientSocket.recvfrom(BUFF_SIZE)
67  y = np.frombuffer(msgFromServer[0], dtype=input_array.dtype)
68  logging.debug(output_array[cnt*BUFF_SIZE:(cnt+1)*BUFF_SIZE-1].size)
69  output_array[cnt*BUFF_SIZE:(cnt+1)*BUFF_SIZE] = y
70  if ((cnt+1)*BUFF_SIZE >= total_size):
71  logging.debug("Reached size to receive")
72  break;
73  else:
74  cnt = cnt + 1
75  return output_array
76 
77 if __name__ == '__main__':
78  main(args)
int main()
Definition: tb_fmc.cpp:380
def uppercase(input_array, total_size, fpga_ip, fpga_port, debug_level)
Definition: custom.py:41