Ejemplo n.º 1
0
 protected override void Build(BufferAllocator allocator, ConnectedLayerGroups connectedLayerGroups, NNInitParameters initPars)
 {
     var oclInitPars = (OpenCLNNInitParameters)initPars;
     CreateOpenCLContext(oclInitPars);
     inputBuffer = connectedLayerGroups.InputBuffer;
     outputBuffer = connectedLayerGroups.OutputBuffer;
 }
Ejemplo n.º 2
0
        public void TestDispose()
        {
            const int sliverSize = 4; // 4 floats = 16 bytes
            const int floatNumSlices = 11; // 11 slices per buffer, to test various cases
            BufferAllocator<float> bufferAllocator = new BufferAllocator<float>(sliverSize * floatNumSlices, 1, sizeof(float));

            float continuousDuration = 2.4f;
            int discreteDuration = (int)Math.Round(continuousDuration + 1);
            float[] tempBuffer = AllocateSmall4FloatArray(discreteDuration, sliverSize);

            // check that allocated, then freed, buffers are used first for next allocation
            Buf<float> buffer = bufferAllocator.Allocate();
            bufferAllocator.Free(buffer);
            Buf<float> buffer2 = bufferAllocator.Allocate();
            HoloDebug.Assert(buffer.Data == buffer2.Data);

            // free it again so stream can get it
            bufferAllocator.Free(buffer);

            DenseSampleFloatStream stream = new DenseSampleFloatStream(0, bufferAllocator, sliverSize);
            stream.Append(new Slice<Sample, float>(new Buf<float>(-6, tempBuffer), sliverSize));

            Verify4SliceFloatStream(stream, 0);

            // have stream drop it; should free buffer
            stream.Dispose();

            // make sure we get it back again
            buffer2 = bufferAllocator.Allocate();
            HoloDebug.Assert(buffer.Data == buffer2.Data);
        }
Ejemplo n.º 3
0
 public World(AudioGraphImpl audioGraphImpl)
 {
     // Each buffer is one second of audio at two stereo channels x 4 bytes per 32-bit-float sample x sample rate.
     // Allocate 128 of them, arbitrarily.
     _audioAllocator = new BufferAllocator <float>(2 * 4 * Constants.SampleRateHz, 128, sizeof(float));
     _audioGraph     = audioGraphImpl;
 }
Ejemplo n.º 4
0
        protected override void Build(BufferAllocator allocator, ConnectedLayerGroups connectedLayerGroups, NNInitParameters initPars)
        {
            InitializeInputAndOutput(connectedLayerGroups);

            BuildForwardComputation(allocator, connectedLayerGroups, (CPUNNInitParameters)initPars);
            if (IsBackwardEnabled) BuildBackwardComputation(connectedLayerGroups);
        }
Ejemplo n.º 5
0
        public void TestMethod1()
        {
            var alloc     = new BufferAllocator(new byte[8 * 1024 * 40]);
            var consumers = new Task[100];

            for (var i = 0; i < consumers.Length; i++)
            {
                var consumer = Task.Run(async() =>
                {
                    var buffer = alloc.AllocateAsync(new Random().Next(4 * 1024, 32 * 1024));
                    try
                    {
                        if (buffer.Array[buffer.Offset] == 0xff)
                        {
                            throw new Exception("the same buffer was asigned");
                        }
                        buffer.Array[buffer.Offset] = 0xff;
                        await Task.Delay(200);
                    }
                    finally
                    {
                        buffer.Array[buffer.Offset] = 0x00;
                        alloc.Free(buffer);
                    }
                });
                consumers[i] = consumer;
            }
            Task.WaitAll(consumers);
        }
        internal HolofunkBassAsioInput(HolofunkBassAsio bassAsio, int asioChannel, BufferAllocator<float> audioAllocator)
        {
            m_bassAsio = bassAsio;
            m_asioChannel = asioChannel;

            // buffer one second's worth of audio; that will always be more than we need to look at
            m_recentPastStream = new DenseSampleFloatStream(
                default(Time<Sample>),
                audioAllocator,
                1, // input channels are mono
                maxBufferedDuration: Clock.TimepointRateHz);

            m_inputToInputPushStreamAsioProc = new ASIOPROC(InputToInputPushStreamAsioProc);

            // create input push stream; this receives data pushed from ASIO's input, and feeds the mixer
            m_inputPushStream = (StreamHandle)Bass.BASS_StreamCreatePush(
                Clock.TimepointRateHz,
                HolofunkBassAsio.InputChannelCount,
                BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT,
                new IntPtr(m_asioChannel));

            // connect to ASIO input channel
            CheckError(BassAsio.BASS_ASIO_ChannelEnable(
                HolofunkBassAsio.IsInputChannel,
                m_asioChannel,
                m_inputToInputPushStreamAsioProc,
                new IntPtr(m_asioChannel)));

            // join right channel if we have more than one input channel
            // (this is not generalized for >stereo)
            if (HolofunkBassAsio.InputChannelCount == 2) {
                CheckError(BassAsio.BASS_ASIO_ChannelJoin(HolofunkBassAsio.IsInputChannel, 1, m_asioChannel));
            }

            // set format and rate of input channel
            CheckError(BassAsio.BASS_ASIO_ChannelSetFormat(HolofunkBassAsio.IsInputChannel, m_asioChannel, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT));
            CheckError(BassAsio.BASS_ASIO_ChannelSetRate(HolofunkBassAsio.IsInputChannel, m_asioChannel, Clock.TimepointRateHz));

            // add input push stream to mixer
            CheckError(BassMix.BASS_Mixer_StreamAddChannel(
                (int)m_bassAsio.MixerHStream,
                (int)m_inputPushStream,
                BASSFlag.BASS_MIXER_DOWNMIX | BASSFlag.BASS_MIXER_NORAMPIN));

            // set up the input effects (aka microphone effects)
            m_inputPushEffects = AllEffects.CreateLoopEffectSet(m_inputPushStream, m_bassAsio.BaseForm);

            // connect peak level meter to input push stream
            m_plmRec = new DSP_PeakLevelMeter((int)m_inputPushStream, 0);
            m_plmRec.Notification += new EventHandler(Plm_Rec_Notification);

            // Register DSPPROC handler for input channel.  Make sure to hold the DSPPROC itself.
            // See documentation for BassAsioHandler.InputChannel
            m_inputDspProc = new DSPPROC(InputDspProc);

            // set up our recording DSP -- priority 10 hopefully means "run first first first!"
            CheckError(Bass.BASS_ChannelSetDSP((int)m_inputPushStream, m_inputDspProc, new IntPtr(0), 10) != 0);
        }
Ejemplo n.º 7
0
 public Session(Connection clientConnection, BufferAllocator bufferAllocator)
 {
     _clientConnection = clientConnection;
     _bufferAllocator  = bufferAllocator;
     _request          = new Request(this);
     _response         = new Response(this);
     _clientHandler    = new ClientHandler(this, _clientConnection);
     _serverHandler    = new ServerHandler(this);
 }
Ejemplo n.º 8
0
        public void Send(ICopyable data)
        {
            /*
             * Assemble an AHPacket:
             */
            if (_header == null)
            {
                AHHeader ahh = new AHHeader(_hops, _ttl, _source, _dest, _options);
                _header        = MemBlock.Copy(new CopyList(PType.Protocol.AH, ahh));
                _header_length = _header.Length;
            }
            byte[] ah_packet;
            int    packet_length;
            int    packet_offset;

            //Try to get the shared BufferAllocator, useful when
            //we don't know how big the data is, which in general
            //is just as expensive as doing a CopyTo...
            BufferAllocator ba = Interlocked.Exchange <BufferAllocator>(ref _buf_alloc, null);

            if (ba != null)
            {
                try {
                    ah_packet     = ba.Buffer;
                    packet_offset = ba.Offset;
                    int tmp_off = packet_offset;
                    tmp_off      += _header.CopyTo(ah_packet, packet_offset);
                    tmp_off      += data.CopyTo(ah_packet, tmp_off);
                    packet_length = tmp_off - packet_offset;
                    ba.AdvanceBuffer(packet_length);
                }
                catch (System.Exception x) {
                    throw new SendException(false, "could not write the packet, is it too big?", x);
                }
                finally {
                    //Put the BA back
                    Interlocked.Exchange <BufferAllocator>(ref _buf_alloc, ba);
                }
            }
            else
            {
                //Oh well, someone else is using the buffer, just go ahead
                //and allocate new memory:
                packet_offset = 0;
                packet_length = _header_length + data.Length;
                ah_packet     = new byte[packet_length];
                int off_to_data = _header.CopyTo(ah_packet, 0);
                data.CopyTo(ah_packet, off_to_data);
            }
            MemBlock mb_packet = MemBlock.Reference(ah_packet, packet_offset, packet_length);

            /*
             * Now we announce this packet, the AHHandler will
             * handle routing it for us
             */
            _n.HandleData(mb_packet, _from, this);
        }
Ejemplo n.º 9
0
        internal void InitializeAlgo(BufferAllocator allocator, LearningRule rule, ConnectedLayer[] connectedLayers, CPUNNInitParameters initPars)
        {
            Contract.Requires(rule != null);
            Contract.Requires(connectedLayers != null);
            Contract.Requires(connectedLayers.Length > 0);
            Contract.Requires(initPars != null);

            Rule = rule;
            ConnectedLayers = connectedLayers;
            RunParallel = initPars.RunParallel;
            Ininitalize(allocator);
        }
Ejemplo n.º 10
0
        public void TestBufferAllocator()
        {
            BufferAllocator<float> bufferAllocator = new BufferAllocator<float>(FloatNumSlices * 2048, 1, sizeof(float));
            Buf<float> f = bufferAllocator.Allocate();
            HoloDebug.Assert(f.Data.Length == FloatSliverSize * 1024 * FloatNumSlices);

            Buf<float> f2 = bufferAllocator.Allocate();
            HoloDebug.Assert(f.Data.Length == f2.Data.Length);
            bufferAllocator.Free(f2);
            Buf<float> f3 = bufferAllocator.Allocate();
            HoloDebug.Assert(f2.Data == f3.Data); // need to pull from free list first
        }
Ejemplo n.º 11
0
 private void BuildForwardComputation(BufferAllocator allocator, ConnectedLayerGroups connectedLayerGroups, CPUNNInitParameters initPars)
 {
     forwardComputeGroups = new LayerForwardCompute[connectedLayerGroups.Groups.Count][];
     for (int groupIndex = 0; groupIndex < connectedLayerGroups.Groups.Count; groupIndex++)
     {
         var group = connectedLayerGroups.Groups[groupIndex];
         forwardComputeGroups[groupIndex] = new LayerForwardCompute[group.Count];
         for (int layerIndex = 0; layerIndex < group.Count; layerIndex++)
         {
             forwardComputeGroups[groupIndex][layerIndex] = CreateLayerForwardCompute(group[layerIndex], initPars);
         }
     }
 }
Ejemplo n.º 12
0
        protected void ListenThread()
        {
            Thread.CurrentThread.Name = "udp_listen_thread";
            BufferAllocator ba        = new BufferAllocator(8 + Int16.MaxValue);
            EndPoint        end       = new IPEndPoint(IPAddress.Any, 0);
            int             rec_bytes = 0;

            MonitorLogSwitch();
            ProtocolLog.Monitor.SwitchedSetting += MonitorLogSwitch;

            while (1 == _running)
            {
                int max = ba.Capacity;
                try {
                    rec_bytes = _s.ReceiveFrom(ba.Buffer, ba.Offset, max,
                                               SocketFlags.None, ref end);
                } catch (SocketException x) {
                    if ((1 == _running) && ProtocolLog.UdpEdge.Enabled)
                    {
                        ProtocolLog.Write(ProtocolLog.UdpEdge, x.ToString());
                    }
                }

                if (rec_bytes < 8)
                {
                    continue;
                }

                int remoteid = NumberSerializer.ReadInt(ba.Buffer, ba.Offset);
                int localid  = NumberSerializer.ReadInt(ba.Buffer, ba.Offset + 4);

                MemBlock packet_buffer = MemBlock.Reference(ba.Buffer, ba.Offset + 8, rec_bytes - 8);
                ba.AdvanceBuffer(rec_bytes);

                if (localid < 0)
                {
                    // Negative ids are control messages
                    HandleControlPacket(remoteid, localid, packet_buffer, end);
                }
                else
                {
                    HandleDataPacket(remoteid, localid, packet_buffer, end, null);
                }
            }
            ProtocolLog.Monitor.SwitchedSetting -= MonitorLogSwitch;
            //Let everyone know we are out of the loop
            _listen_finished_event.Set();
            _s.Close();
            //Allow garbage collection
            _s = null;
        }
        public unsafe void GetMessageForEventRecord()
        {
            var allocator = new BufferAllocator();

            var record = new EventRecordBuilder(allocator);

            record.AddArg(32);
            var recordPtr = record.Build();

            var info = new TraceEventInfoBuilder(allocator);

            info.EventMessage          = "Foo %1 Bar";
            info.PropertyCount         = 1;
            info.TopLevelPropertyCount = 1;
            info.EventPropertyInfos    = new[] {
                new EVENT_PROPERTY_INFO {
                    InType  = TDH_IN_TYPE.INT32,
                    OutType = TDH_OUT_TYPE.INT,
                    countAndCountPropertyIndex   = 1,
                    lengthAndLengthPropertyIndex = 4
                }
            };
            var infoPtr = info.Build();

            var    context        = new ParseTdhContext();
            var    formatProvider = CultureInfo.InvariantCulture;
            string message;

            var sw = new Stopwatch();

            var formatter = new NativeTdhFormatter();

            sw.Restart();
            for (int i = 0; i < 100000; ++i)
            {
                var eventInfo = new EventInfo {
                    EventRecord        = (IntPtr)recordPtr.Ptr,
                    TraceEventInfo     = (IntPtr)infoPtr.Ptr,
                    TraceEventInfoSize = (UIntPtr)infoPtr.Size
                };
                message = formatter.GetMessageForEvent(
                    eventInfo, context, formatProvider);
                Assert.Equal("Foo 32 Bar", message);
            }
            sw.Stop();
            output.WriteLine("EMF: {0}", sw.ElapsedMilliseconds);

            allocator.Dispose();
        }
Ejemplo n.º 14
0
        public BlockAllocator(AllocatorManager.AllocatorHandle handle, int budgetInBytes)
        {
            m_bufferAllocator = new BufferAllocator(budgetInBytes, ms_BlockSize, handle);
            m_nextPtr         = 0;
            var blocks = (budgetInBytes + ms_BlockSize - 1) >> ms_Log2BlockSize;

            m_allocations = new UnsafeIntList(blocks, handle);

            for (int i = 0; i < blocks; ++i)
            {
                m_allocations.Add(0);
            }

            m_currentBlockIndex = -1;
        }
Ejemplo n.º 15
0
 public ChunkBuffer()
 {
     //Setup all buffer allocators
     VertexBuffers    = new UniformBuffer(false);
     BufferAllocators = new BufferAllocator[Sizes.Length];
     unsafe
     {
         long *buf = (long *)VertexBuffers.Update();
         for (int i = 0; i < Sizes.Length; i++)
         {
             BufferAllocators[i] = new BufferAllocator(Sizes[i], Counts[i], false, PixelInternalFormat.Rgba8ui);
             buf[i * 2]          = BufferAllocators[i].BufferTex.View.GetTextureHandle().SetResidency(Residency.Resident);
         }
         VertexBuffers.UpdateDone();
     }
 }
Ejemplo n.º 16
0
 public SocketState(TcpEdgeListener tel)
 {
     _sock_to_rs       = new Hashtable();
     _sock_to_constate = new ListDictionary();
     _con_socks        = new ArrayList();
     ListenSock        = tel._listen_sock;
     _socks_to_send    = new ArrayList();
     AllSockets        = new ArrayList();
     ReadSocks         = new ArrayList();
     ErrorSocks        = new ArrayList();
     WriteSocks        = new ArrayList();
     Run = true;
     /* Use a shared BufferAllocator for all Edges */
     BA = new BufferAllocator(2 + Int16.MaxValue);
     ListenSock.Listen(10);
     TEL = tel;
 }
Ejemplo n.º 17
0
        public MultiDrawIndirectMesh(GL gl, nuint allocatorSize, DrawElementsType drawElementsType, Layer layers = Layer.Layer0)
        {
            const nuint reasonable_max_object_count = 21_000u;

            ID    = Guid.NewGuid();
            Layer = layers;

            _GL                = gl;
            _CommandBuffer     = new BufferObject <DrawElementsIndirectCommand>(gl);
            _BufferAllocator   = new BufferAllocator(gl, allocatorSize);
            _VertexArrayObject = new VertexArrayObject(gl);
            _ModelBuffer       = new BufferObject <Matrix4x4>(gl, reasonable_max_object_count, BufferStorageMask.MapWriteBit);

            _VertexArrayObject.AllocateVertexBufferBinding(0u, _BufferAllocator);
            _VertexArrayObject.AllocateVertexBufferBinding(1u, _ModelBuffer, 0, 1u);
            _DrawElementsType = drawElementsType;
        }
Ejemplo n.º 18
0
        public WeightRelatedValues(BufferAllocator allocator, ConnectedLayer[] layers)
        {
            Contract.Requires(allocator != null);
            Contract.Requires(layers != null);
            Contract.Requires(layers.Length > 0);

            buffers = new IntRange[layers.Length][];
            for (int layerIndex = 0; layerIndex < layers.Length; layerIndex++)
            {
                var wib = layers[layerIndex].WeightedInputBuffers;

                buffers[layerIndex] = new IntRange[wib.Length];
                for (int buffIndex = 0; buffIndex < wib.Length; buffIndex++)
                {
                    buffers[layerIndex][buffIndex] = allocator.Alloc(wib[buffIndex].WeightBuffer.Size);
                }
            }
            this.layers = layers;
        }
Ejemplo n.º 19
0
 public SimulationEdgeListener(int id, double loss_prob, TAAuthorizer ta_auth, bool use_delay)
 {
     _edges       = new Hashtable();
     _use_delay   = use_delay;
     _sync        = new object();
     _ba          = new BufferAllocator(Int16.MaxValue);
     _listener_id = id;
     _ploss_prob  = loss_prob;
     if (ta_auth == null)
     {
         _ta_auth = new ConstantAuthorizer(TAAuthorizer.Decision.Allow);
     }
     else
     {
         _ta_auth = ta_auth;
     }
     _tas = new ArrayList();
     _tas.Add(TransportAddressFactory.CreateInstance("b.s://" + _listener_id));
     _rand = new Random();
 }
Ejemplo n.º 20
0
        public void TestLimitedBufferingStream()
        {
            const int sliverSize = 4; // 4 floats = 16 bytes
            const int floatNumSlices = 11; // 11 slices per buffer, to test various cases
            BufferAllocator<float> bufferAllocator = new BufferAllocator<float>(sliverSize * floatNumSlices, 1, sizeof(float));

            float[] tempBuffer = AllocateSmall4FloatArray(20, sliverSize);

            DenseSampleFloatStream stream = new DenseSampleFloatStream(0, bufferAllocator, sliverSize, 5);
            stream.Append(new Slice<Sample, float>(new Buf<float>(-7, tempBuffer), 0, 11, sliverSize));
            HoloDebug.Assert(stream.DiscreteDuration == 5);
            Slice<Sample, float> slice = stream.GetNextSliceAt(stream.DiscreteInterval);
            HoloDebug.Assert(slice[0, 0] == 6f);

            stream.Append(new Slice<Sample, float>(new Buf<float>(-8, tempBuffer), 11, 5, sliverSize));
            HoloDebug.Assert(stream.DiscreteDuration == 5);
            HoloDebug.Assert(stream.InitialTime == 11);
            slice = stream.GetNextSliceAt(stream.DiscreteInterval);
            HoloDebug.Assert(slice[0, 0] == 11f);
        }
Ejemplo n.º 21
0
        /// <summary>The thread acting as the ISource for Ethernet, this is where
        /// reading of the TAP is performed.  Use Subscribe to receive the packets
        /// coming from here.</summary>
        /// <remarks>The same max MTU byte array is always read into.  This is then
        /// copied to a minimum sized MemBlock and send to the subscriber. </remarks>
        protected void ReadLoop()
        {
            byte[]          read_buffer = new byte[MTU];
            BufferAllocator ba          = new BufferAllocator(MTU, 1.1);

            while (_running)
            {
                int length = -1;
                try {
                    length = _tap.Read(read_buffer);
                } catch (ThreadInterruptedException x) {
                    if (_running && ProtocolLog.Exceptions.Enabled)
                    {
                        ProtocolLog.Write(ProtocolLog.Exceptions, x.ToString());
                    }
                } catch (Exception e) {
                    ProtocolLog.WriteIf(ProtocolLog.Exceptions, e.ToString());
                }

                if (length == 0 || length == -1)
                {
                    ProtocolLog.WriteIf(IpopLog.TapLog, "Couldn't read TAP");
                    continue;
                }

                Array.Copy(read_buffer, 0, ba.Buffer, ba.Offset, length);
                MemBlock packet = MemBlock.Reference(ba.Buffer, ba.Offset, length);
                ba.AdvanceBuffer(length);

                Subscriber s = _sub;
                if (s != null)
                {
                    try {
                        s.Handle(packet, this);
                    } catch (Exception e) {
                        ProtocolLog.WriteIf(ProtocolLog.Exceptions, e.ToString());
                    }
                }
            }
        }
Ejemplo n.º 22
0
 public ReceiveState(TcpEdge e, BufferAllocator ba)
 {
     Edge = e;
     _s   = e.Socket;
     _ba  = ba;
 }
 public TraceEventInfoBuilder(BufferAllocator allocator)
 {
     this.allocator = allocator;
 }
Ejemplo n.º 24
0
 static SimulationEdgeListener()
 {
   _el_map = new Dictionary<TransportAddress.TAType, Dictionary<int, SimulationEdgeListener>>();
   _ba = new BufferAllocator(Int16.MaxValue);
   _rand = Node.SimulatorRandom;
 }
Ejemplo n.º 25
0
    /**
     * This is a System.Threading.ThreadStart delegate
     * We loop waiting for edges that need to send,
     * or data on the socket.
     *
     * This is the only thread that can touch the socket,
     * therefore, we do not need to lock the socket.
     */
    protected void ListenThread()
    {
      Thread.CurrentThread.Name = "udp_listen_thread";
      BufferAllocator ba = new BufferAllocator(8 + Int16.MaxValue);
      EndPoint end = new IPEndPoint(IPAddress.Any, 0);

      DateTime last_debug = DateTime.UtcNow;
      int debug_period = 5000;
      bool logging = ProtocolLog.Monitor.Enabled;
      int rec_bytes = 0;
      while(1 == _running) {
        if(logging) {
          DateTime now = DateTime.UtcNow;
          if(last_debug.AddMilliseconds(debug_period) < now) {
            last_debug = now;
            ProtocolLog.Write(ProtocolLog.Monitor, String.Format("I am alive: {0}", now));
          }
        }

        int max = ba.Capacity;
        try {
          rec_bytes = _s.ReceiveFrom(ba.Buffer, ba.Offset, max,
                                          SocketFlags.None, ref end);
        } catch(SocketException x) {
          if((1 == _running) && ProtocolLog.UdpEdge.Enabled) {
            ProtocolLog.Write(ProtocolLog.UdpEdge, x.ToString());
          }
        }

        if(rec_bytes < 8) {
          continue;
        }

        int remoteid = NumberSerializer.ReadInt(ba.Buffer, ba.Offset);
        int localid = NumberSerializer.ReadInt(ba.Buffer, ba.Offset + 4);

        MemBlock packet_buffer = MemBlock.Reference(ba.Buffer, ba.Offset + 8, rec_bytes - 8);
        ba.AdvanceBuffer(rec_bytes);

        if( localid < 0 ) {
          // Negative ids are control messages
          HandleControlPacket(remoteid, localid, packet_buffer, null);
        } else {
          HandleDataPacket(remoteid, localid, packet_buffer, end, null);
        }
      }
      //Let everyone know we are out of the loop
      _listen_finished_event.Set();
      _s.Close();
      //Allow garbage collection
      _s = null;
    }
Ejemplo n.º 26
0
 protected virtual void Ininitalize(BufferAllocator allocator) { }
Ejemplo n.º 27
0
 internal void InitializeAlgo(BufferAllocator allocator, LearningRule learningRule, ConnectedLayer[] connectedLayer)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 28
0
        protected override void InitializeLearningAlgorithms(BufferAllocator allocator, LearningLayerGroups learningLayerGroups, NNInitParameters initPars)
        {
            algorithms = new LearningAlgorithm[learningLayerGroups.Count];
            var biAlgos = new LinkedList<LearningAlgorithm>();
            var aeAlgos = new LinkedList<LearningAlgorithm>();

            int idx = 0;
            foreach (var group in learningLayerGroups)
            {
                var algo = CreateAlgorithmForRule(group.Rule);
                algo.InitializeAlgo(allocator, group.Rule, group.ConnectedLayers.ToArray(), (CPUNNInitParameters)initPars);
                algorithms[idx++] = algo;
                if (algo.Rule.IsBeforeIterationRule) biAlgos.AddLast(algo);
                if (algo.Rule.IsErrorBasedRule) aeAlgos.AddLast(algo);
            }

            beforeIterationAlgorithms = biAlgos.ToArray();
            errorBasedAlgorithms = aeAlgos.ToArray();
        }
Ejemplo n.º 29
0
        public void TestStreamAppending()
        {
            const int sliverSize = 4; // 4 floats = 16 bytes
            const int floatNumSlices = 11; // 11 slices per buffer, to test various cases
            BufferAllocator<float> bufferAllocator = new BufferAllocator<float>(sliverSize * floatNumSlices, 1, sizeof(float));

            float[] buffer = AllocateSmall4FloatArray(floatNumSlices, sliverSize);

            DenseSampleFloatStream stream = new DenseSampleFloatStream(0, bufferAllocator, sliverSize);

            unsafe {
                fixed (float* f = buffer) {
                    IntPtr pf = new IntPtr(f);

                    stream.Append(floatNumSlices, pf);
                }
            }

            HoloDebug.Assert(stream.DiscreteDuration == floatNumSlices);

            HoloDebug.Assert(Verify4SliceFloatStream(stream, 0) == 11);

            // clear original buffer to test copying back into it
            for (int i = 0; i < buffer.Length; i++) {
                buffer[i] = 0;
            }

            unsafe {
                fixed (float* f = buffer) {
                    IntPtr pf = new IntPtr(f);
                    stream.CopyTo(stream.DiscreteInterval, pf);
                }
            }

            DenseSampleFloatStream stream2 = new DenseSampleFloatStream(0, bufferAllocator, sliverSize);
            stream2.Append(new Slice<Sample, float>(new Buf<float>(-3, buffer), sliverSize));

            HoloDebug.Assert(Verify4SliceFloatStream(stream2, 0) == 11);
        }
Ejemplo n.º 30
0
 public EotStreamReader(Stream stream, BufferAllocator bufferAllocator)
     : base(stream, bufferAllocator)
 {
 }
Ejemplo n.º 31
0
 public void SetUp()
 {
     //Create space for up to 1000 objects
     _bufferAllocator = new BufferAllocator(1000 * 512, 512);
 }
Ejemplo n.º 32
0
 public HttpProxy()
 {
     _listener        = new TcpListener(_port);
     _bufferAllocator = new BufferAllocator(new byte[1024 * 1024]);
     _listener.ConnectionRequested += OnConnectionRequested;
 }
Ejemplo n.º 33
0
 static AHSender()
 {
     SenderFactory.Register("ah", CreateInstance);
     _buf_alloc = new BufferAllocator(System.UInt16.MaxValue);
 }
Ejemplo n.º 34
0
        public void HandleData(AHHeader header, ICopyable payload, ISender ret_path, object st)
        {
            AHState    state = _state; //Read the state, it can't change after the read
            Connection next_con;
            //Check to see if we can use a Leaf connection:
            int dest_idx = state.Leafs.IndexOf(header.Destination);

            if (dest_idx >= 0)
            {
                next_con = state.Leafs[dest_idx];
            }
            else
            {
                var alg = state.GetRoutingAlgo(header);
                Pair <Connection, bool> result = alg.NextConnection(ret_path as Edge, header);
                if (result.Second)
                {
                    //Send a response exactly back to the node that sent to us
                    var resp_send = new AHSender(_n, ret_path, header.Source,
                                                 AHSender.DefaultTTLFor(_n.NetworkSize),
                                                 AHHeader.Options.Exact, header.Hops);
                    MemBlock data = payload as MemBlock;
                    if (data == null)
                    {
                        // Try to get the shared BufferAllocator, useful when we don't know
                        // how big the data is, which in general is just as expensive as
                        // doing a CopyTo...
                        BufferAllocator ba = Interlocked.Exchange <BufferAllocator>(ref _ba, null);
                        if (ba != null)
                        {
                            try {
                                int length = payload.CopyTo(ba.Buffer, ba.Offset);
                                data = MemBlock.Reference(ba.Buffer, ba.Offset, length);
                                ba.AdvanceBuffer(length);
                            } catch (System.Exception x) {
                                throw new SendException(false, "could not write the packet, is it too big?", x);
                            } finally {
                                Interlocked.Exchange <BufferAllocator>(ref _ba, ba);
                            }
                        }
                        else
                        {
                            data = MemBlock.Copy(payload);
                        }
                    }
                    _n.HandleData(data, resp_send, this);
                }
                next_con = result.First;
            }
            //Send it on:
            if (next_con != null)
            {
                //Now we do the sending:
                var new_packet = new CopyList(PType.Protocol.AH,
                                              header.IncrementHops(),
                                              payload);
                try {
                    next_con.State.Edge.Send(new_packet);
                }
                catch (SendException) {
                    //Just drop the packet...
                }
            }
        }
Ejemplo n.º 35
0
        protected override void Built(BufferAllocator allocator, ConnectedLayerGroups connectedLayerGroups, NNInitParameters initPars)
        {
            // Create buffer:
            oclValueBuffer = oclContext.CreateBuffer<float>(allocator.Size, ComputeMemoryFlags.ReadWrite);

            // Fill with zeros: 
            // TODO: Add this stuff to and OpenCLUtils class or sumthin
            int size = 1000;
            int remain = allocator.Size % size;
            float[] zeros = new float[size];

            if (remain != 0) oclQueue.Write(oclValueBuffer, zeros, 0, remain, false);
            for (int i = remain; i < allocator.Size; i += size)
            {
                oclQueue.Write(oclValueBuffer, zeros, i, size, false);
            }

            oclQueue.ComputeCommandQueue.Finish();
        }
Ejemplo n.º 36
0
        public void TestSparseSampleByteStream()
        {
            const int sliverSize = 2 * 2 * 4; // uncompressed 2x2 RGBA image... worst case
            const int bufferSlivers = 10;
            BufferAllocator<byte> allocator = new BufferAllocator<byte>(sliverSize * bufferSlivers, 1, sizeof(float));

            byte[] appendBuffer = new byte[sliverSize];
            for (int i = 0; i < sliverSize; i++) {
                appendBuffer[i] = (byte)i;
            }

            SparseSampleByteStream stream = new SparseSampleByteStream(10, allocator, sliverSize);
            stream.Append(11, new Slice<Frame, byte>(new Buf<byte>(-9, appendBuffer), sliverSize));

            // now let's get it back out
            Slice<Frame, byte> slice = stream.GetClosestSliver(11);
            HoloDebug.Assert(slice.Duration == 1);
            HoloDebug.Assert(slice.SliverSize == sliverSize);
            for (int i = 0; i < sliverSize; i++) {
                HoloDebug.Assert(slice[0, i] == (byte)i);
            }

            // now let's copy it to intptr
            byte[] target = new byte[sliverSize];
            unsafe {
                fixed (byte* p = target) {
                    IntPtr pp = new IntPtr(p);
                    stream.CopyTo(11, pp);
                }
            }

            for (int i = 0; i < sliverSize; i++) {
                HoloDebug.Assert(target[i] == (byte)i);
            }

            SparseSampleByteStream stream2 = new SparseSampleByteStream(10, allocator, sliverSize);
            unsafe {
                fixed (byte* p = target) {
                    IntPtr pp = new IntPtr(p);
                    stream2.Append(11, pp);
                }
            }

            Slice<Frame, byte> slice2 = stream2.GetClosestSliver(12);
            HoloDebug.Assert(slice2.Duration == 1);
            HoloDebug.Assert(slice2.SliverSize == sliverSize);
            for (int i = 0; i < sliverSize; i++) {
                HoloDebug.Assert(slice2[0, i] == (byte)i);
            }

            // now verify looping and shutting work as expected
            for (int i = 0; i < appendBuffer.Length; i++) {
                appendBuffer[i] += (byte)appendBuffer.Length;
            }
            stream2.Append(21, new Slice<Frame, byte>(new Buf<byte>(-10, appendBuffer), sliverSize));

            Slice<Frame, byte> slice3 = stream2.GetClosestSliver(12);
            HoloDebug.Assert(slice3.Duration == 1);
            HoloDebug.Assert(slice3.SliverSize == sliverSize);
            HoloDebug.Assert(slice3[0, 0] == (byte)0);
            Slice<Frame, byte> slice4 = stream2.GetClosestSliver(22);
            HoloDebug.Assert(slice4.Duration == 1);
            HoloDebug.Assert(slice4.SliverSize == sliverSize);
            HoloDebug.Assert(slice4[0, 0] == (byte)sliverSize);

            stream2.Shut((ContinuousDuration)20);

            // now the closest sliver to 32 should be the first sliver
            Slice<Frame, byte> slice5 = stream2.GetClosestSliver(32);
            HoloDebug.Assert(slice5.Duration == 1);
            HoloDebug.Assert(slice5.SliverSize == sliverSize);
            HoloDebug.Assert(slice5[0, 0] == (byte)0);
            // and 42, the second
            Slice<Frame, byte> slice6 = stream2.GetClosestSliver(42);
            HoloDebug.Assert(slice6.Duration == 1);
            HoloDebug.Assert(slice6.SliverSize == sliverSize);
            HoloDebug.Assert(slice6[0, 0] == (byte)sliverSize);
        }
Ejemplo n.º 37
0
 protected override void InitializeLearningAlgorithms(BufferAllocator allocator, Learning.LearningLayerGroups learningLayerGroups, NNInitParameters initPars)
 {
 }
Ejemplo n.º 38
0
 static SimulationEdgeListener()
 {
   _listener_map = new Dictionary<int, SimulationEdgeListener>();
   _ba = new BufferAllocator(Int16.MaxValue);
 }
Ejemplo n.º 39
0
        protected override void Built(BufferAllocator allocator, ConnectedLayerGroups connectedLayerGroups, NNInitParameters initPars)
        {
            // Create buffer:
            valueBuffer = new float[allocator.Size];

            // RTLR:
            if ((StructuralElementFlags & NNStructuralElement.RTLRInformation) != 0)
            {
                pValProp = new PValuePropagator(connectedLayerGroups.IndexTable, forwardComputeGroups.SelectMany(g => g));
            }
        } 
Ejemplo n.º 40
0
        /// <summary>Allows the game to perform any initialization it needs to before starting to run.</summary>
        /// <remarks>This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.</remarks>
        protected override void Initialize()
        {
            new Test(GraphicsDevice).RunAllTests();

            // HORRIBLE HACK: just ensure the statics are initialized
            string s = PlayerEffectSpaceModel.EffectSettings[0].LeftLabel;

            m_audioAllocator = new BufferAllocator<float>(2 * 4 * Clock.TimepointRateHz, 128, sizeof(float));

            m_holofunkBass = new HolofunkBass(m_clock, m_audioAllocator);
            m_holofunkBass.StartASIO();

            m_kinect = new HolofunKinect(GraphicsDevice, BodyFrameUpdate);

            m_viewportSize = m_kinect.ViewportSize;

            m_videoAllocator = new BufferAllocator<byte>(64 * MagicNumbers.HeadCaptureBytes, 128, 1);

            base.Initialize();

            // oh dear

            m_holofunkBass.SetBaseForm(m_primaryForm, MagicNumbers.MaxStreamCount);

            Window.Title = "Holofunk Alpha";
            Window.AllowUserResizing = true;

            /*
            object nativeWindow = Window.NativeWindow;
            System.Windows.Forms.Form asForm = nativeWindow as System.Windows.Forms.Form;
            asForm.SetDesktopBounds(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            //asForm.SetDesktopBounds(100, 100, (int)(m_viewportSize.X * 2), (int)(m_viewportSize.Y * 2));
            */
        }
Ejemplo n.º 41
0
        public void TestStream()
        {
            BufferAllocator<float> bufferAllocator = new BufferAllocator<float>(FloatNumSlices * 2048, 1, sizeof(float));

            DenseSampleFloatStream stream = new DenseSampleFloatStream(0, bufferAllocator, FloatSliverSize);

            HoloDebug.Assert(stream.DiscreteDuration == 0);

            var interval = new Interval<Sample>(0, 10);
            Slice<Sample, float> firstSlice = stream.GetNextSliceAt(interval);
            HoloDebug.Assert(firstSlice.IsEmpty());

            // Now let's fill a float array...
            float[] buffer = new float[FloatNumSlices * FloatSliverSize];
            Duration<Sample> floatNumSlicesDuration = FloatNumSlices;
            Slice<Sample, float> tempSlice = new Slice<Sample, float>(new Buf<float>(-1, buffer), FloatSliverSize);
            PopulateFloatSlice(tempSlice);

            // now append in chunks
            stream.Append(tempSlice.SubsliceOfDuration(tempSlice.Duration / 2));
            stream.Append(tempSlice.SubsliceStartingAt(tempSlice.Duration / 2));

            HoloDebug.Assert(stream.InitialTime == 0);
            HoloDebug.Assert(stream.DiscreteDuration == FloatNumSlices);

            Slice<Sample, float> theSlice = stream.GetNextSliceAt(stream.DiscreteInterval);

            VerifySlice(theSlice);
            HoloDebug.Assert(theSlice.Duration == floatNumSlicesDuration);
        }
Ejemplo n.º 42
0
        public void TestStreamSlicing()
        {
            const int sliverSize = 4; // 4 floats = 16 bytes
            const int floatNumSlices = 11; // 11 slices per buffer, to test various cases
            BufferAllocator<float> bufferAllocator = new BufferAllocator<float>(sliverSize * floatNumSlices, 1, sizeof(float));

            float[] buffer = AllocateSmall4FloatArray(floatNumSlices * 2, sliverSize);

            DenseSampleFloatStream stream = new DenseSampleFloatStream(0, bufferAllocator, sliverSize);
            stream.Append(new Slice<Sample, float>(new Buf<float>(-4, buffer), sliverSize));

            // test getting slices from existing stream
            Slice<Sample, float> beforeFirst = stream.GetNextSliceAt(new Interval<Sample>((-2), 4));
            // should return slice with duration 2
            HoloDebug.Assert(beforeFirst.Duration == 2);

            Slice<Sample, float> afterLast = stream.GetNextSliceAt(new Interval<Sample>(19, 5));
            HoloDebug.Assert(afterLast.Duration == 3);

            // now get slice across the buffer boundary, verify it is split as expected
            Interval<Sample> splitInterval = new Interval<Sample>(7, 8);
            Slice<Sample, float> beforeSplit = stream.GetNextSliceAt(splitInterval);
            HoloDebug.Assert(beforeSplit.Duration == 4);

            Slice<Sample, float> afterSplit = stream.GetNextSliceAt(splitInterval.SubintervalStartingAt(beforeSplit.Duration));
            HoloDebug.Assert(afterSplit.Duration == beforeSplit.Duration);
            float lastBefore = beforeSplit[3, 0];
            float firstAfter = afterSplit[0, 0];
            HoloDebug.Assert(lastBefore + 1 == firstAfter);

            float[] testStrideCopy = new float[] {
                0, 0, 1, 1, 0, 0,
                0, 0, 2, 2, 0, 0,
            };

            stream.AppendSliver(testStrideCopy, 2, 2, 6, 2);

            Slice<Sample, float> lastSliver = stream.GetNextSliceAt(new Interval<Sample>(22, 1));
            HoloDebug.Assert(lastSliver.Duration == 1);
            HoloDebug.Assert(lastSliver[0, 0] == 1f);
            HoloDebug.Assert(lastSliver[0, 1] == 1f);
            HoloDebug.Assert(lastSliver[0, 2] == 2f);
            HoloDebug.Assert(lastSliver[0, 3] == 2f);

            Slice<Sample, float> firstSlice = stream.GetNextSliceAt(new Interval<Sample>(-2, 100));
            HoloDebug.Assert(firstSlice.Duration == 11);
        }
Ejemplo n.º 43
0
    protected void ListenThread()
    {
      Thread.CurrentThread.Name = "udp_listen_thread";
      BufferAllocator ba = new BufferAllocator(8 + Int16.MaxValue);
      EndPoint end = new IPEndPoint(IPAddress.Any, 0);
      int rec_bytes = 0;
      MonitorLogSwitch();
      ProtocolLog.Monitor.SwitchedSetting += MonitorLogSwitch;

      while(1 == _running) {
        int max = ba.Capacity;
        try {
          rec_bytes = _s.ReceiveFrom(ba.Buffer, ba.Offset, max,
                                          SocketFlags.None, ref end);
        } catch(SocketException x) {
          if((1 == _running) && ProtocolLog.UdpEdge.Enabled) {
            ProtocolLog.Write(ProtocolLog.UdpEdge, x.ToString());
          }
        }

        if(rec_bytes < 8) {
          continue;
        }

        int remoteid = NumberSerializer.ReadInt(ba.Buffer, ba.Offset);
        int localid = NumberSerializer.ReadInt(ba.Buffer, ba.Offset + 4);

        MemBlock packet_buffer = MemBlock.Reference(ba.Buffer, ba.Offset + 8, rec_bytes - 8);
        ba.AdvanceBuffer(rec_bytes);

        if( localid < 0 ) {
          // Negative ids are control messages
          HandleControlPacket(remoteid, localid, packet_buffer, end);
        } else {
          HandleDataPacket(remoteid, localid, packet_buffer, end, null);
        }
      }
      ProtocolLog.Monitor.SwitchedSetting -= MonitorLogSwitch;
      //Let everyone know we are out of the loop
      _listen_finished_event.Set();
      _s.Close();
      //Allow garbage collection
      _s = null;
    }
Ejemplo n.º 44
0
 static SimulationEdgeListener()
 {
     _el_map = new Dictionary <TransportAddress.TAType, Dictionary <int, SimulationEdgeListener> >();
     _ba     = new BufferAllocator(Int16.MaxValue);
     _rand   = Node.SimulatorRandom;
 }
Ejemplo n.º 45
0
 public ReceiveState(TcpEdge e, BufferAllocator ba) {
   Edge = e;
   _s = e.Socket;
   _ba = ba;
 }
Ejemplo n.º 46
0
 public SocketState(TcpEdgeListener tel) {
   _sock_to_rs = new Hashtable();
   _sock_to_constate = new ListDictionary();
   _con_socks = new ArrayList();
   ListenSock = tel._listen_sock;
   _socks_to_send = new ArrayList();
   AllSockets = new ArrayList();
   ReadSocks = new ArrayList();
   ErrorSocks = new ArrayList();
   WriteSocks = new ArrayList();
   Run = true;
   /* Use a shared BufferAllocator for all Edges */
   BA = new BufferAllocator(2 + Int16.MaxValue);
   ListenSock.Listen(10);
   TEL = tel;
 }
Ejemplo n.º 47
0
        /**
         * This is a System.Threading.ThreadStart delegate
         * We loop waiting for edges that need to send,
         * or data on the socket.
         *
         * This is the only thread that can touch the socket,
         * therefore, we do not need to lock the socket.
         */
        protected void ListenThread()
        {
            Thread.CurrentThread.Name = "udp_listen_thread";
            BufferAllocator ba  = new BufferAllocator(8 + Int16.MaxValue);
            EndPoint        end = new IPEndPoint(IPAddress.Any, 0);

            DateTime last_debug   = DateTime.UtcNow;
            int      debug_period = 5000;
            bool     logging      = ProtocolLog.Monitor.Enabled;
            int      rec_bytes    = 0;

            while (1 == _running)
            {
                if (logging)
                {
                    DateTime now = DateTime.UtcNow;
                    if (last_debug.AddMilliseconds(debug_period) < now)
                    {
                        last_debug = now;
                        ProtocolLog.Write(ProtocolLog.Monitor, String.Format("I am alive: {0}", now));
                    }
                }

                int max = ba.Capacity;
                try {
                    rec_bytes = _s.ReceiveFrom(ba.Buffer, ba.Offset, max,
                                               SocketFlags.None, ref end);
                } catch (SocketException x) {
                    if ((1 == _running) && ProtocolLog.UdpEdge.Enabled)
                    {
                        ProtocolLog.Write(ProtocolLog.UdpEdge, x.ToString());
                    }
                }

                if (rec_bytes < 8)
                {
                    continue;
                }

                int remoteid = NumberSerializer.ReadInt(ba.Buffer, ba.Offset);
                int localid  = NumberSerializer.ReadInt(ba.Buffer, ba.Offset + 4);

                MemBlock packet_buffer = MemBlock.Reference(ba.Buffer, ba.Offset + 8, rec_bytes - 8);
                ba.AdvanceBuffer(rec_bytes);

                if (localid < 0)
                {
                    // Negative ids are control messages
                    HandleControlPacket(remoteid, localid, packet_buffer, null);
                }
                else
                {
                    HandleDataPacket(remoteid, localid, packet_buffer, end, null);
                }
            }
            //Let everyone know we are out of the loop
            _listen_finished_event.Set();
            _s.Close();
            //Allow garbage collection
            _s = null;
        }
Ejemplo n.º 48
0
        public void TestStreamShutting()
        {
            const int sliverSize = 4; // 4 floats = 16 bytes
            const int floatNumSlices = 11; // 11 slices per buffer, to test various cases
            BufferAllocator<float> bufferAllocator = new BufferAllocator<float>(sliverSize * floatNumSlices, 1, sizeof(float));

            float continuousDuration = 2.4f;
            int discreteDuration = (int)Math.Round(continuousDuration + 1);
            float[] buffer = AllocateSmall4FloatArray(discreteDuration, sliverSize);
            DenseSampleFloatStream stream = new DenseSampleFloatStream(0, bufferAllocator, sliverSize, useContinuousLoopingMapper: true);
            stream.Append(new Slice<Sample, float>(new Buf<float>(-5, buffer), sliverSize));

            // OK, time to get this fractional business right.
            stream.Shut((ContinuousDuration)continuousDuration);
            HoloDebug.Assert(stream.IsShut);

            // now test looping
            Interval<Sample> interval = new Interval<Sample>(0, 10);
            // we expect this to be [0, 1, 2, 0, 1, 0, 1, 2, 0, 1]
            // or rather, [0>3], [0>2], [0>3], [0>2]
            Slice<Sample, float> slice = stream.GetNextSliceAt(interval);
            HoloDebug.Assert(slice.Duration == 3);
            HoloDebug.Assert(slice[0, 0] == 0f);
            HoloDebug.Assert(slice[2, 0] == 2f);

            interval = interval.SubintervalStartingAt(slice.Duration);
            slice = stream.GetNextSliceAt(interval);
            HoloDebug.Assert(slice.Duration == 2);
            HoloDebug.Assert(slice[0, 0] == 0f);
            HoloDebug.Assert(slice[1, 0] == 1f);

            interval = interval.SubintervalStartingAt(slice.Duration);
            slice = stream.GetNextSliceAt(interval);
            HoloDebug.Assert(slice.Duration == 3);
            HoloDebug.Assert(slice[0, 0] == 0f);
            HoloDebug.Assert(slice[2, 0] == 2f);

            interval = interval.SubintervalStartingAt(slice.Duration);
            slice = stream.GetNextSliceAt(interval);
            HoloDebug.Assert(slice.Duration == 2);
            HoloDebug.Assert(slice[0, 0] == 0f);
            HoloDebug.Assert(slice[1, 0] == 1f);

            interval = interval.SubintervalStartingAt(slice.Duration);
            HoloDebug.Assert(interval.IsEmpty);

            DenseSampleFloatStream stream2 = new DenseSampleFloatStream(0, bufferAllocator, sliverSize, useContinuousLoopingMapper: false);
            stream2.Append(new Slice<Sample, float>(new Buf<float>(-5, buffer), sliverSize));
            stream2.Shut((ContinuousDuration)continuousDuration);
            interval = new Interval<Sample>(0, 10);
            slice = stream2.GetNextSliceAt(interval);
            HoloDebug.Assert(slice.Duration == 3);
            HoloDebug.Assert(slice[0, 0] == 0f);
            HoloDebug.Assert(slice[2, 0] == 2f);

            interval = interval.SubintervalStartingAt(slice.Duration);
            slice = stream2.GetNextSliceAt(interval);
            HoloDebug.Assert(slice.Duration == 3);
            HoloDebug.Assert(slice[0, 0] == 0f);
            HoloDebug.Assert(slice[1, 0] == 1f);

            interval = interval.SubintervalStartingAt(slice.Duration);
            slice = stream2.GetNextSliceAt(interval);
            HoloDebug.Assert(slice.Duration == 3);
            HoloDebug.Assert(slice[0, 0] == 0f);
            HoloDebug.Assert(slice[2, 0] == 2f);

            interval = interval.SubintervalStartingAt(slice.Duration);
            slice = stream2.GetNextSliceAt(interval);
            HoloDebug.Assert(slice.Duration == 1);
            HoloDebug.Assert(slice[0, 0] == 0f);
        }
Ejemplo n.º 49
0
 public SimulationEdgeListener(int id, double loss_prob, TAAuthorizer ta_auth, bool use_delay)
 {
   _edges = new Hashtable();
   _use_delay = use_delay;
   _sync = new object();
   _ba = new BufferAllocator(Int16.MaxValue);
   _listener_id = id;
   _ploss_prob = loss_prob;
   if (ta_auth == null) {
     _ta_auth = new ConstantAuthorizer(TAAuthorizer.Decision.Allow);
   } else {
     _ta_auth = ta_auth;
   }
   _tas = new ArrayList();
   _tas.Add(TransportAddressFactory.CreateInstance("b.s://" + _listener_id));
   _rand = new Random();
 }
Ejemplo n.º 50
0
 public VoxelCache(string cacheName) : base(cacheName)
 {
     IndexBuffer = new BufferAllocator(cacheName, VoxelConstants.IndexBlockSz, VoxelConstants.IndexBlockCnt, BufferUsage.Index, ImageFormat.R8G8B8A8UInt);
 }
Ejemplo n.º 51
0
 static AHSender() {
   SenderFactory.Register("ah", CreateInstance);
   _buf_alloc = new BufferAllocator(System.UInt16.MaxValue);
 }
Ejemplo n.º 52
0
        public void TestStreamChunky()
        {
            const int sliverSize = 4; // 4 floats = 16 bytes
            const int floatNumSlices = 11; // 11 slices per buffer, to test various cases
            const int biggestChunk = 5; // max size of slice to copy in middle loop
            BufferAllocator<float> bufferAllocator = new BufferAllocator<float>(sliverSize * floatNumSlices, 1, sizeof(float));

            DenseSampleFloatStream stream = new DenseSampleFloatStream(0, bufferAllocator, sliverSize);

            HoloDebug.Assert(stream.DiscreteDuration == 0);

            float f = 0;
            float[] tinyBuffer = new float[biggestChunk * sliverSize];
            for (int i = 0; i < 100; i++) {
                for (int c = 1; c <= 5; c++) {
                    for (int j = 0; j < c; j++) {
                        tinyBuffer[j * sliverSize] = f;
                        tinyBuffer[j * sliverSize + 1] = f + 0.25f;
                        tinyBuffer[j * sliverSize + 2] = f + 0.5f;
                        tinyBuffer[j * sliverSize + 3] = f + 0.75f;
                        f++;
                    }
                    Slice<Sample, float> tempSlice = new Slice<Sample, float>(
                        new Buf<float>(-2, tinyBuffer), 0, c, sliverSize);
                    stream.Append(tempSlice);
                }
            }

            // Now after this we will need a verification loop.
            BufferAllocator<float> bigBufferAllocator = new BufferAllocator<float>(sliverSize * 1024, 1, sizeof(float));
            DenseSampleFloatStream bigStream = new DenseSampleFloatStream(0, bigBufferAllocator, sliverSize);

            stream.CopyTo(stream.DiscreteInterval, bigStream);

            HoloDebug.Assert(Verify4SliceFloatStream(stream, 0) == 1500);
            HoloDebug.Assert(Verify4SliceFloatStream(bigStream, 0) == 1500);

            DenseSampleFloatStream stream2 = new DenseSampleFloatStream(0, bufferAllocator, sliverSize);
            bigStream.CopyTo(bigStream.DiscreteInterval, stream2);

            HoloDebug.Assert(Verify4SliceFloatStream(stream2, 0) == 1500);
        }
Ejemplo n.º 53
0
 static SimulationEdgeListener()
 {
     _listener_map = new Dictionary <int, SimulationEdgeListener>();
     _ba           = new BufferAllocator(Int16.MaxValue);
 }
 public EventRecordBuilder(BufferAllocator allocator)
 {
     this.allocator = allocator;
 }