<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sebastian Ahmed on Medium]]></title>
        <description><![CDATA[Stories by Sebastian Ahmed on Medium]]></description>
        <link>https://medium.com/@sebastian-ahmed?source=rss-2692d6a677fe------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zPaumbAVIaW7EA9QHpcjMA.jpeg</url>
            <title>Stories by Sebastian Ahmed on Medium</title>
            <link>https://medium.com/@sebastian-ahmed?source=rss-2692d6a677fe------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 16:16:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sebastian-ahmed/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Satori for Engineers]]></title>
            <link>https://sebastian-ahmed.medium.com/satori-for-engineers-b94fa68aa3f3?source=rss-2692d6a677fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/b94fa68aa3f3</guid>
            <category><![CDATA[leadership-development]]></category>
            <category><![CDATA[inspiration]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[engineering-mangement]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Sebastian Ahmed]]></dc:creator>
            <pubDate>Tue, 27 Apr 2021 02:23:09 GMT</pubDate>
            <atom:updated>2021-04-28T15:12:16.143Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FBFD2B_o-C66ENjL" /><figcaption>Photo by <a href="https://unsplash.com/@tianshu?utm_source=medium&amp;utm_medium=referral">Tianshu Liu</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>“If there is only one job you have as a leader, it is to care”</blockquote><blockquote>“If there is only one job you have as an architect, it is to simplify”</blockquote><blockquote>“Always ask the question ‘is there a better normal?’”</blockquote><blockquote>“Learning is set of beliefs and actions consistent with open mindedness”</blockquote><blockquote>“Teaching is not about showing how smart you are”</blockquote><blockquote>“Build something that requires you to learn something new”</blockquote><blockquote>“Surround yourself with people who think even bigger than you”</blockquote><blockquote>“Influence by creating, coaching and demonstrating”</blockquote><blockquote>“Complexity is a state of failure that is always correctable”</blockquote><blockquote>“One must work very hard to be able to work smart”</blockquote><blockquote>“Solve for the long term”</blockquote><blockquote>“Kindness adds while transactions limit at best”</blockquote><blockquote>“Your goals should be big enough to build the careers of others”</blockquote><blockquote>“Always yield the right of way to great ideas”</blockquote><blockquote>“Keep improving the ‘user-experience’ that is you”</blockquote><blockquote>“Open more doors than you close”</blockquote><blockquote>“Become more coachable”</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b94fa68aa3f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Write-count-limited attributes in Python]]></title>
            <link>https://sebastian-ahmed.medium.com/write-count-limited-attributes-in-python-a08cef02cde?source=rss-2692d6a677fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/a08cef02cde</guid>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[encapsulation]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Sebastian Ahmed]]></dc:creator>
            <pubDate>Sun, 21 Mar 2021 22:40:40 GMT</pubDate>
            <atom:updated>2021-03-22T02:54:07.732Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*q-zNbbeVGRAn7j-B" /><figcaption>Photo by <a href="https://unsplash.com/@kaip?utm_source=medium&amp;utm_medium=referral">Kai Pilger</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this post I demonstrate a solution to generalize the creation of class attributes for various <em>write-count-limited</em> scenarios, such as:</p><ol><li><strong>Class-level</strong> <strong>constant</strong> attributes (read-only)</li><li><strong>Write-once</strong> attributes, i.e. can be written once and then become read-only</li><li><strong>Object-level constant</strong> attributes (read-only)</li><li>Attributes which can be <strong>written a number of times</strong> <strong>up to a specified limit</strong> before becoming read-only</li></ol><h3>Generalizing</h3><p>Upon inspection, it should become clear that</p><blockquote>all of the above are actually cases of a general write-count limit in the range 0-N.</blockquote><p>Specifically, for each case above, the write-count-limit is as follows:</p><ol><li>write-count-limit = 0 (but the constant must be supplied at the class-level)</li><li>write-count-limit = 1 (if not initialized) or 2 (if initialized)</li><li>write-count-limit = 1 and initialized (i.e. the initializer consumes the single write-count with the “constant”)</li><li>write-count-limit = N (if not initialized) or N+1 (if initialized)</li></ol><p>Note that we distinguished cases where an attribute was or wasn’t initialized (i.e. written with an initial value in a client object’s __init__() method).</p><p>What should happen when we attempt exceed the write-count-limit?</p><p>We should raise an appropriate <strong>exception</strong> so that application code can decide how to handle it. Disabling exceptions should be possible on a per-attribute basis.</p><p>Also, wouldn’t it be great to be able to get <em>state </em>information for a particular attribute of a specific object as to whether it is now read-only, how many writes have been performed or the specified limit?</p><h3>Solution</h3><p>If you want to jump straight to the code, go here:</p><p><a href="https://github.com/sebastian-ahmed/python-etc/tree/main/write_limited_attributes">https://github.com/sebastian-ahmed/python-etc/tree/main/write_limited_attributes</a></p><p>The class which implements the general write-count-limited attribute is defined in WriteLimited.py and examples of each case is simulated in test.py</p><p>What about <em>properties</em>? Can’t we just use these? The short answer is yes, but the solution would not be generalized enough, i.e., each case would require maintaining a shadow raw-attribute as well as a count attribute. That’s pretty heavy if you need this sort of behavior on a number of attributes.</p><p>Also, there is no way to enforce (or catch) the user of a class to modify the underlying raw-attributes. Working around the descriptor interface is more involved and thus a less likely mechanism for inadvertent or “lazy” circumventing.</p><p>Instead of using properties, we leverage the descriptor protocol and a custom exception</p><blockquote>The descriptor protocol allows us to create a descriptor class that encapsulates and abstracts the behaviors at the attribute-level.</blockquote><p>Along with such a class, a <strong>custom exception</strong> is defined which can thus be finely controlled (as opposed to raising a more generic AttributeError<em> </em>or other exception). For this purpose, the descriptor raises the WriteLimitError custom exception. Had we used properties, the exception raising would need to be done in the client-class.</p><h3>Usage Example</h3><p>In order to better illustrate the concepts, below is a code snippet of a valid use of the WriteLimited descriptor class within a client class that implements the various write-limited scenarios:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/41d02c31413b94314d4d2bc5e1f8da21/href">https://medium.com/media/41d02c31413b94314d4d2bc5e1f8da21/href</a></iframe><p>It should be noted that the class-level constants do not have any initialization because the constant is passed directly to the descriptor object. It can also be noted that all but attribute_2 will raise an exception if written beyond their limit. Lastly, I will re-iterate that all the assignments in the __init__() method count as a single write.</p><p>If we instantiate an object of this class, print it and then attempt to write to attribute_5 11 times (one more than allowed), we get the following output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*wGEZphtcI_Bw3LHJ8sHDNw.png" /><figcaption>Example usage output</figcaption></figure><p>The custom exception provides a useful message telling us the offending attribute name and pre-set max write-count.</p><p>Note that in the screen capture above, we were able to print out the object attribute <em>write-count</em> and <em>is_read-only</em> information. This is made possible by some special <strong>attribute</strong> <strong>utility methods</strong> provided by the class, specifically WriteLimited.getattr_wcount(instance,name) and WriteLimited.getattr_ro(instance,name). These <em>static </em>methods work with a similar interface to the data-model <em>getattr</em> methods in that they take an object reference (instance) and a name of the attribute. How do these work?</p><h3>Shadow Attributes (gory details)</h3><p>If you are familiar with descriptors, you’ll know that the interface only supports a few methods relating to setting/getting/deleting.</p><p>The solution to this problem (of providing some sort of per-attribute level state) is not immediately obvious. It involves creating and maintaining a set of <strong>shadow attributes</strong> at the client-object <strong>instance</strong> level. Essentially, each time we set an instance-level attribute, we shadow this operation by setting/updating shadow attributes that maintain the per-client-instance state.</p><p>In order to support the getattr_*() utility methods, there needs to be a way to make sure that the shadow attributes are up-to-date for the requested instance. To achieve this, both the __get__() and __set__() descriptor interface methods perform updates to the shadow attributes. The __get__() method is actually called by the utility methods as a <strong>priming</strong> operation which allows the shadow attributes to be updated since reads have no <em>side-effects</em>.</p><p>For complete details, see <a href="https://github.com/sebastian-ahmed/python-etc/blob/main/write_limited_attributes/WriteLimited.py">WriteLimited.py</a>.</p><h3>Summary</h3><p>In this post I’ve provided a relatively straightforward and generalized interface for creating various write-limited attribute applications including exception support to catch limit violations. This approach is much lighter weight than using properties which natively only support instance-level read-only semantics (by omission of the <em>setter </em>method).</p><p>In regard to implementation details, I’ve shown that the <em>descriptor protocol</em> approach provides the necessary mechanics to generalize the solution and encapsulate the limit/access-violation checking with integrated exception mechanics. I’ve also shown how dynamically generated <em>shadow attributes</em> can provide a rich state visibility layer for attributes,</p><blockquote>making attributes stateful beyond their mere assigned values</blockquote><p>As with all my posts, working code is available and in a state ready for re-use:</p><p><a href="https://github.com/sebastian-ahmed/python-etc/tree/main/write_limited_attributes">https://github.com/sebastian-ahmed/python-etc/tree/main/write_limited_attributes</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a08cef02cde" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Decorating bound-methods in Python — a general and scalable solution]]></title>
            <link>https://sebastian-ahmed.medium.com/decorating-bound-methods-in-python-a-general-and-scalable-solution-b16579c3a469?source=rss-2692d6a677fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/b16579c3a469</guid>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[patterns]]></category>
            <dc:creator><![CDATA[Sebastian Ahmed]]></dc:creator>
            <pubDate>Tue, 16 Mar 2021 02:45:27 GMT</pubDate>
            <atom:updated>2021-03-18T23:00:33.172Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aWUDCVBVy6OSuotm" /><figcaption>Photo by <a href="https://unsplash.com/@briewilly?utm_source=medium&amp;utm_medium=referral">Chad Montano</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Decorating bound-methods in Python — a general and scalable solution</h3><p>Decorators in Python can quickly become a complicated matter when dealing with bound-methods (i.e. class-instance bound function calls). In some cases a basic decorator is required. In other cases, we would like to supply<strong> parameters</strong> to the decorator itself. We also would like to <strong>extend/modify</strong> decorator definitions and not have to implement the complexities each time. Lastly we would like to control execution before, during and after a wrapped method call and having each such <strong>phase</strong> be configurable.</p><p>After experimenting with a variety of approaches, I have come up with a generalized solution that enables highly configurable and extensible bound-method decorators which use the elegance of <strong>object-oriented</strong> (OO) mechanics and the Python <a href="https://docs.python.org/3/howto/descriptor.html"><strong>descriptor protocol</strong></a><strong> </strong>(optional reading and not for the feint of heart).</p><p>In this article I describe the solution and the features it provides. It will also become quite clear why this is in fact a somewhat tricky problem that requires a deep understanding of the Python interpreter <em>data-model</em> dynamics. Despite these complexities, the solution presented is very easy to use. Besides providing a re-usable solution, I hope this article also goes some way to deepen your understanding of the Python language.</p><h3>Decorator Semantics</h3><p>In order to properly appreciate the challenges involved and to better define the problem statement, it’s important to elaborate the underlying semantics of function decorators and how things quickly get complicated when we require variability in the declarations and thus dynamics.</p><p>Consider the following decorator usage styles:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e646f155d8b31d30dcfee67831f83ee/href">https://medium.com/media/6e646f155d8b31d30dcfee67831f83ee/href</a></iframe><p>Let’s compare and contrast these styles to comprehend what actually happens:</p><ul><li>The statement Decorator(method1) must return a <em>callable</em> so that invocations of method1 follow the semantics of a bound method-call. This syntax seems consistent with initializing a Decorator object with the wrapped function object reference as the initializer argument. This suggests that the Decorator object (let’s call it decorator) is in fact itself a <em>callable</em>, but even more-so, it must be callable in a way that captures the bound object of the method-call (more on this complication later)</li><li>The statement Decorator(param1=&quot;foo&quot;)(method2) must also return a <em>callable</em>, but this syntax looks more compounded, in the sense that the Decorator object initialization takes some parameter(s) other than the wrapped function and this is followed by a <em>call </em>on this object with the wrapped function object reference, i.e. the call occurs when this line in the class definition is interpreted. It suffices to say however, that this call only happens once, and subsequent calls are on the returned callable. Such subsequent calls must also be on a bound object</li></ul><p>The point here is that despite the <em>syntactic sugar</em> of the decorator syntax, the underlying dynamics of the effective assignments could not be more different and this is what creates trouble in trying to support both formats.</p><h3>Usage goals</h3><p>Now that we’ve shown how a subtle difference in high-level syntax creates completely different mechanisms under the hood, lets formalize what makes for a complete and general solution for bound-method decorators. Consider a class with methods we may wish to decorate. We wish to do the following:</p><ul><li>Decorate specific bound-methods with a decorator</li><li>In some cases, the decorator will have no parameters and can use a typical syntax without parentheses, e.g. @Decorator</li><li>In other cases, we would like parameters to be passed to the decorator, e.g. @Decorator(*args,**kwargs)</li></ul><p>Each decorator should have the option to do the following (let’s call this the <em>decorator functionality</em>):</p><ul><li>Optionally perform actions before calling the wrapped method with the ability to operate on the bound object instance</li><li>Optionally override the default calling of the wrapped method in a particular way (e.g. fixing some argument) as a bound method call</li><li>Optionally perform actions after calling the wrapped method with the ability to operate on the bound object instance. This should also allow the return value of the wrapped method to be modified for example</li></ul><p>We would also like to create specializations of the decorator because we may want variations in the behaviors of the <em>decorator functionality</em>. The wrapped calling sub-phases are shown in the figure below. Any such sequence must be defined in a base class so that it can be <strong>overridden</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*tqbaqO7t28MuVEs_jEizxw.png" /><figcaption>Drawing by Sebastian Ahmed</figcaption></figure><h3>Solution Overview</h3><p>The solution requires handling two underlying mechanisms with some common structures. It turns out that the second case (decorator with parameters) is in fact the simpler case. First we will discuss the essence of the solution for each case.</p><h4>Using a dedicated class</h4><p>It perhaps goes without saying that using a dedicated class is the best approach to solving this problem. The main reasons are the following:</p><ul><li>Classes are great for problems that require <em>stateful</em> behaviors</li><li>Classes provide construction semantics (via __init__())</li><li>Classes provide callability semantics (via __call__())</li><li>Classes provide the ability to <em>extend</em> and <em>override</em></li><li>The <em>descriptor protocol </em>of the Python interpreter is only available via a dedicated class</li></ul><h4>Decorators with parameters</h4><p>This case (case #2 in the previous code example), can be implemented with the simplest approach. The reason is that it can be done completely without the <em>descriptor protocol</em>. Let’s look again at the following line which is the effective representation of the decorator assignment:</p><p>method2=Decorator(param1=&quot;foo&quot;)(method2)</p><p>Here method2 is a bound method (i.e. one that takes the bound object reference typically denoted as self as the first argument). Three things happen when this line is executed by the interpreter during what I would refer to as the <em>decoration phase </em>(i.e.<em>, </em>the point at which the interpreter is executing this line as it reads the class definition):</p><ul><li>Reading from left to right, we first initialize a new Decorator object which calls the Decorator.__init__(param1=&quot;foo&quot;) method and <em>returns </em>a reference to a new Decorator object. Let’s refer to this <em>anonymous </em>object as decorator. It’s anonymous because we never assign its reference directly to any variable</li><li>Continuing to read the statement, we now have an object reference decorator which we subsequently <em>call</em>,<em> </em>which under the hood will look like decorator.__call__(method2). Again, this call occurs during the <em>decoration phase</em>. We’re not referring to any bound method calls here</li><li>The decorator object call method returns a <em>callable</em> which represents the wrapped method call matching the previous figure showing the decorated call broken out in sub-phases</li></ul><p>There is nothing especially complicated here, except that we must make sure to understand that when the now wrapped method2 is invoked as a bound-method call (e.g., some_object.method2()), that the first argument in the callable is a reference to the bound instance. It turns out that the interpreter takes care of providing this reference which is passed into the callable call because this <em>callable</em> is local to each object of the class which defines method2. This is important to understand because the other case acts differently.</p><h4>Decorators without parameters</h4><p>This is where things get a a bit more tricky. Let’s dissect the mechanics of what such a decorator assignment actually does:</p><p>method1 = Decorator(method1) # equivalent to @Decorator</p><p>This seems harmless enough. But what is it actually doing? Clearly it is just a an initializer call of the Decorator class which passes the method reference (method1) in this case as the only argument. This means that method1 is assigned a reference to a Decorator object (let’s call it decorator). There is no subsequent <em>call</em> to get a callable. So, once the interpreter has processed this line, we effectively have:</p><p>method1 = decorator # A class-variable reference to a Decorator object</p><p>Bound-method calls of method1 thus will result in calling the decorator class-level object (i.e. this object is bound to the class which defines method1).</p><blockquote>What makes this different is that now all bound calls are actually bound to the decorator object</blockquote><p>The difference is that in the previous case (parameterized-decorator), a function object (<em>callable</em>) is provided to method2 during the decoration phase, which is always called as a bound-method call, such that calls to this <em>callable</em> follow regular bound-method call semantics.</p><p>In the parameter-less case, the mechanics resulted in a Decorator initializer method being called. <strong>There is no way to return a function object from a class initializer call</strong>. An initializer always returns a reference to the initialized object. In this case, the returned decorator object is just an associated object (via <em>composition</em>), so when method1() is called (during a bound-method call), decorator.__call__() is called. The call is bound, but it’s bound to the decorator object, <strong>not the client object</strong>. This may appear to be an inconvenience, but any other behavior would in fact be nonsense.</p><p>How do we provide the bound object instance reference to this __call__()method?</p><blockquote>The solution to this problem requires leveraging the Python “<em>descriptor protocol”</em></blockquote><p>To get into all the background and mechanics of the <em>descriptor protocol </em>would fill several posts, so let’s not go there. Instead, we can focus on the relevant dynamics which allow us to <em>intercept</em> and <em>capture </em>the caller’s instance reference <em>before</em> the decorator.__call__() method is invoked.</p><p>To make this work, we add the __get__() method in the Decorator class, which, via Python’s wonderful data-model <em>type-emulation </em>system (affectionately known as <em>duck-typing</em>), turns a Decorator class into a <strong>descriptor</strong>.</p><blockquote>A <em>descriptor </em>allows <em>attributes</em> to be implemented via a class-bound object which has access to the instance reference of any object of that client class.</blockquote><p>You may have already used descriptors, albeit indirectly if you have leveraged <strong>properties</strong>. Properties are just a very common pattern implemented upon the descriptor protocol framework</p><p>Once the Decorator class becomes a <em>descriptor</em>, it turns the decorator object into an <em>attribute</em> of the client class . Descriptors are always class-bound (because attribute definitions and method definitions are in fact class-bound). When a descriptor is accessed as a callable via an object attribute,</p><blockquote>some wonderful things happen under the hood:</blockquote><ul><li>The __get__() method is called in the first phase. This is called when the attribute is <em>read</em>. It is during this time that the caller’s instance reference is passed to our <em>descriptor </em>object. We <strong>save</strong> this information for the subsequent call phase (this is the crux of the magic)</li><li>Following that, there is a function call attempt which will target the __call__() method of the <em>descriptor </em>object. At this point in time, we have the bound object(instance) reference (this was saved in the last step)</li></ul><p>So one can see that it is via the __get__() method, that we can <em>capture </em>the calling object reference and then we use this captured reference during the call phase to implement the decorator call-phases (with full access to the calling object reference) to implement the earlier diagram. Just to be clear, both __get__() and __call__() are called by the interpreter in sequence when performing a calling action on an attribute implemented by a descriptor. I hope you’re still with me because that was the heavy part.</p><h3>Example Code and Source</h3><p>The source-code for the bound-method decorator base-class BMDecorate and an associated test are available in my personal GitHub project here:</p><p><a href="https://github.com/sebastian-ahmed/python-etc/tree/main/bound_method_decorators">https://github.com/sebastian-ahmed/python-etc/tree/main/bound_method_decorators</a></p><p>It is best to demonstrate the solution via an example. The example below creates a specialization of BMDecorate called my_decorator which overrides all three phases (this is equivalent to the test.py code in the above GitHub link:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7a61a07e662f79cb58fd6d4e172881e/href">https://medium.com/media/e7a61a07e662f79cb58fd6d4e172881e/href</a></iframe><p>This example demonstrates that specializations of BMDecorate can be used with our without parameters. Running the above example generates the following output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*6XuGVbb3YRcGgTNaP_z5EA.png" /><figcaption>Output of running <a href="https://github.com/sebastian-ahmed/python-etc/blob/main/bound_method_decorators/test.py">https://github.com/sebastian-ahmed/python-etc/blob/main/bound_method_decorators/test.py</a></figcaption></figure><p>The output above shows in detail all the phases and steps that occur, including the actual <em>decoration</em> phase which occurs when the interpreter is processing the <strong>A</strong> and <strong>B</strong> class definitions (which declare the decorators).</p><h3>Conclusion</h3><p>In this article I presented a general solution for bound-method decorators via a specialized class which can be extended for custom use. Providing the flexibility for both bare and parametrized decorators along with multi-phased execution required getting into the guts of the <em>descriptor protocol </em>which is the fundamental mechanism in Python to implement properties and other intelligent attributes.</p><p>I mostly wrote this article so that anyone who is wishing to decorate bound-methods can find and re-use this solution. Lastly, I hope that it provided you some increased depth in your Python OO knowledge.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b16579c3a469" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Dataclasses With Properties and Pandas]]></title>
            <link>https://medium.com/swlh/python-dataclasses-with-properties-and-pandas-5c59b05e9131?source=rss-2692d6a677fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c59b05e9131</guid>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[python-dataclass]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Sebastian Ahmed]]></dc:creator>
            <pubDate>Wed, 10 Feb 2021 02:23:58 GMT</pubDate>
            <atom:updated>2021-02-21T01:47:23.804Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u_rw8Ag6WLip728n" /><figcaption>Photo by <a href="https://unsplash.com/@pbernardon?utm_source=medium&amp;utm_medium=referral">Pascal Bernardon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>At some point in my Python OOP journey, I came across <a href="https://docs.python.org/3/library/dataclasses.html"><strong><em>dataclasses</em></strong></a>. I vaguely recall this coming about when generating seemingly repetitive boilerplate code for a class that did little more than containing a rather lengthy data-record. Hoping there was a better way to do this lead me to discover <em>dataclasses</em> which were introduced in Python 3.7 (via <a href="https://www.python.org/dev/peps/pep-0557/">PEP 557</a>).</p><blockquote>In a nutshell, the <strong>dataclasses</strong> make developing and maintaining data-centric classes simpler.</blockquote><p>In this post I wanted to share some discoveries as they relate to more interesting class implementations and also how such “interesting” <em>dataclasses</em> can be easily leveraged by the Python data-analysis module <a href="https://pandas.pydata.org/"><strong><em>pandas</em></strong></a>.</p><h3>An “Interesting” Data-Class</h3><p>The following list constitutes what I would consider “interesting” in the sense of what might happen in real-life when creating a <em>dataclass</em>:</p><ul><li>Properties which generate attribute values — perhaps with no underlying class attribute (i.e. a <em>pure</em> property). These can be thought of as data-processing layers with attribute semantics (vs methods)</li><li>Read-only attributes</li><li>Initializer-only fields</li><li>Properties which generate attribute values based on initializer-only fields</li><li>Attributes initialized with an optional <strong>list</strong> or <strong>dict</strong> type</li><li>Attributes which we do not wish to export to a <em>pandas </em><a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html"><strong>DataFrame</strong></a></li></ul><p>Below is how such a class might look. It should be noted that <em>DataClass_Modern </em>implements all the “interesting” features listed above</p><ul><li><strong>attr5</strong> is a <em>pure</em> property which is <em>read-only</em> and derives its value from the initializer-only field <strong>attr0</strong>. There is no underlying class-variable that reflects the value of <strong>attr5</strong>. Note the <strong>dummy setter</strong>, which was required by the <em>dataclasses</em> module to make it believe it was settable. We also had to define this with the <em>init=False</em> field-control attribute to exclude it from the <strong>__init__()</strong> method generation</li><li><strong>attr4</strong> takes a list for initialization which required a <em>default_factory</em> to return an empty list object when a list was not provided</li><li><strong>_attrHidden</strong> is a copy of the initializer-only attr0 and intended to be <em>hidden</em>. We perform this copy in the <strong>__post_init__()</strong> method</li><li><strong>rand_factory </strong>is a <strong>classmethod</strong> with the sole purpose of generating randomized objects of this class. More on that below as we discuss <em>pandas</em></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e531a71d249858d090179af982504e28/href">https://medium.com/media/e531a71d249858d090179af982504e28/href</a></iframe><h3>Constructing a pandas DataFrame</h3><p>Now that we have defined our <em>dataclass</em> with the various “interesting” features, lets see how seamless it is to get a <em>pandas</em> <strong>DataFrame</strong> <em>constructed</em> from a list of random instances of <em>DataClass_Modern</em>.</p><p>Inspecting the code above, one can immediately see that it is very simple. First we generated a <strong>list</strong> of 100 <em>random </em>objects using our <em>rand_factory()</em> method. Then we simply pass this list directly to the default <strong>DataFrame</strong> constructor.</p><p>Too easy!</p><p>But what about the following?</p><ul><li>Does <strong>attr5 </strong>get exported to the <strong>DataFrame </strong>like we expect?</li><li>Does <strong>attr0</strong> and <strong>_attrHidden</strong> get suppressed from being exported to the <strong>DataFrame</strong> as we might expect?</li></ul><p>The answer to both questions is a big YES. See the output below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*ExM-FX1g6QbrlB_jk1XQ6g.png" /><figcaption>pandas DataFrame construction with dataclasses objects</figcaption></figure><p>Should this be a surprise? Somewhat. How would this have worked if we had not used <em>dataclasses</em>?</p><h3>Constructing a pandas DataFrame with a “classic” class</h3><p>The code snippet below is an equivalent data-centric class definition with all the “interesting” features we wanted using a standard Python user-defined class structure. Now, granted there are a few ways this could have been done, but here we’ll keep things simple and make it as close to a basic user-defined class as possible.</p><p>At first glance it is clear that this took a bit more work (and it is in fact incomplete as we’ll see shortly). Note how we had to treat the <strong>list<em> </em></strong>initializer and how we had to provide our own <strong>__str__() </strong>method. We didn’t however need to provide the dummy <strong>setter</strong> for <strong>attr5</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07a32cc0c21831495ac79ae1610a69d3/href">https://medium.com/media/07a32cc0c21831495ac79ae1610a69d3/href</a></iframe><p>In the code-snippet above, one should see that we are using the special <strong>from_dict</strong> constructor method. This is because we are using the <strong>__dict__</strong> built-in method for the <em>DataClass_Classic</em> objects to get the attributes. This looks simple enough, but what does the <strong>DataFrame</strong> actually look like using this similarly terse approach?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*w_1nEZ5vAhxRoRX26njzMQ.png" /><figcaption>pandas DataFrame construction with “classic” objects</figcaption></figure><p>Two problems:</p><ol><li><strong>_attrHidden</strong> is being exported. <strong>We didn’t want that</strong>. Not surprising because <strong>__dict__</strong> will indeed include “hidden” attributes (i.e. those starting with an underscore). In case you are wondering, a <em>dunder</em> (double-underscore) doesn’t help. In fact, the name-<em>un</em>mangled version (with full class-name prefix) is exported to the <em>DataFrame</em></li><li>Where is <strong>attr5</strong> ?? Nowhere to be found it seems. This is because <strong>__dict__</strong> is a <strong>dict</strong> of <em>class attributes</em> when called on an object. The attr5 attribute is in fact an illusion. It is simply a method decorated with <em>syntactic sugar</em> as an alias for the <strong>getter()</strong> method. Note that adding a dummy <strong>setter </strong>method does not help. Creating attributes this way is a very common pattern in Python because it can provide a data-processing layer with attribute (vs method-calling) semantics</li></ol><p>It turns out that in order to fix the above two issues, we actually need to write a custom method to export a controlled <strong>dict</strong> instead of using the <strong>__dict__</strong> built-in. This is not a huge deal, but now we need to customize and maintain this method which was totally unnecessary when using <em>dataclasses</em>. The full example showing the custom method is contained in the following project:</p><p><a href="https://github.com/sebastian-ahmed/python-etc/blob/main/dataclasses_pandas/example.py">https://github.com/sebastian-ahmed/python-etc/blob/main/dataclasses_pandas/example.py</a></p><p>Having said this, in order to have very advanced control of exporting a user-defined class to a <strong>DataFrame</strong>, the <em>classic </em>approach is still more powerful if you want to do things like control which attributes are not included during construction at run-time or provide object handles as a pandas column (but this is beyond the scope of this article).</p><h3>Observations</h3><p>I would typically mark the last section of any blog post as “Conclusions”, but that would be misleading in this case. Instead we have simply made some observations:</p><ul><li>Using <em>dataclasses</em> reduces repetitive and boilerplate code. For simple data-centric classes the <em>dataclasses</em> based implementation will always be much more succinct (and thus easier to read and maintain). <em>dataclasses </em>have many more features such as provision for comparisons of objects which were not discussed in this article which again makes them very suitable for data-centric applications</li><li>It is possible to implement more advanced attribute behaviors with <em>dataclasses</em> such as read-only generated attributes, initialization-only fields, and factory-based initializers (which can also employ <strong>lambda functions</strong>)</li><li><em>dataclasses</em> provide a very seamless interface to generation of <em>pandas</em> <strong>DataFrame</strong>s. Surprisingly, the construction followed the semantic intent of hidden attributes and pure property-based attributes</li><li>More advanced construction of <strong>DataFrame</strong>s may require the use of standard Python classes. The test of this is usually evidenced by having to contort a <em>dataclass</em> implementation to achieve something that would otherwise be simple with a regular class</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c59b05e9131" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/python-dataclasses-with-properties-and-pandas-5c59b05e9131">Python Dataclasses With Properties and Pandas</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Silicon Innovation Could Massively Scale With More Abstraction]]></title>
            <link>https://medium.com/swlh/how-silicon-innovation-could-massively-scale-with-more-abstraction-4291bb3b94fb?source=rss-2692d6a677fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/4291bb3b94fb</guid>
            <category><![CDATA[verilog]]></category>
            <category><![CDATA[abstraction]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[semiconductors]]></category>
            <category><![CDATA[object-oriented]]></category>
            <dc:creator><![CDATA[Sebastian Ahmed]]></dc:creator>
            <pubDate>Sun, 17 Jan 2021 02:54:27 GMT</pubDate>
            <atom:updated>2021-01-19T00:11:59.463Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*svdD0fSTFbKVZZI8bMS8kA.jpeg" /><figcaption>Photo by Sebastian Ahmed (Sedona, AZ)</figcaption></figure><h3>Decades of logic gates and wires</h3><p>The year is 2021, and the bulk of silicon and FPGA designers are still describing designs at the register-transfer-level (RTL) abstraction. Despite two major evolutions in the Verilog design language, the design subset only gained constructs to better generate and organize wires. This is not to say that there aren’t examples of designs being done at higher-levels such as C++ but this is far from ubiquitous (for reasons I will discuss).</p><p>How should hardware description languages (HDLs) evolve to raise the <strong>aggregate abstraction</strong> of <strong>design-intent</strong>? And more important, why should they?</p><p>In this article I will share my thoughts on how I believe we can free designers and verification engineers to focus more on the key semantics of the desired design-intent with more suitable levels of abstractions. I will also discuss how abstraction and Object-Oriented Programming (OOP) concepts in design can lead to significant increases in productivity, quality, and<strong> innovation</strong>.</p><p>In this article, I am discussing the <strong>design subset</strong> of HDLs (the subset which can be <strong>synthesized</strong> to hardware). It is well-known that the verification and behavioral modeling subsets of languages such as SystemVerilog have long caught up with features of high-level and dynamic languages such as <em>e</em> and Java. In the verification realm, multi-abstraction and multi-paradigms are available, but</p><blockquote>the irony is that verification engineers are still spending much of their time verifying and debugging code even below the design-intent.</blockquote><h3>Abstraction</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vQVXgUqsWUG_pmm7IwsJsw.jpeg" /><figcaption>Photo by Sebastian Ahmed (painting by Piet Mondrian 1921)</figcaption></figure><p>Within the HDL domain, the main issue is the lack of abstraction beyond RTL. What does abstraction mean for HDLs in the context of up-leveling <strong>design-intent</strong>?</p><blockquote>Abstraction is a process of presenting something as a maximally simplified view of concepts for the purpose of higher-order thinking.</blockquote><p>Design, verification, and debugging are all processes involving expressions of thought. The less we must think about, the more efficient we will be, because we can focus our thinking on the salient design-intent concepts.</p><p><strong>Abstraction is not encapsulation</strong>. Pause and think about that for a moment (google if necessary).</p><p>A Verilog module is not an abstraction. It is an encapsulation of RTL-level abstractions. The interface to a Verilog module is still an RTL abstraction. If you wrapped a bundle of wires, and then again wrapped multiple such bundles into yet another bundle you would still end up with wires at each end.</p><p>SystemVerilog for design brought many goodies such as enumerated types, C-style structures, interfaces, and various array-related improvements, but these are merely wire-bundling constructs that need to be unwrapped to use. The level of abstraction never changes except conceptually, in the sense that those concepts cannot be used programmatically.</p><blockquote>A Verilog module no matter how hierarchical, does not abstract beyond RTL semantics.</blockquote><p>A good way to distinguish abstraction from encapsulation in the context of hardware is to think about how one performs actions on the interface of a module. For the purposes of illustration, let us use the venerable FIFO element. An RTL FIFO likely has wires and groupings of wires that represent the read and write port interfaces. There may also be configuration or status wires that need to be routed to some configuration or status handling module. To use the FIFO, one drives or samples <em>logic</em> signals (RTL semantics).</p><p>Below is a Verilog-like pseudo-code snippet that shows how one might use a FIFO if the design subset of the language supported higher abstractions.</p><pre>// Declare and initialize a Fifo object</pre><pre>Fifo fifo=Fifo(depth=128,type=packet_t, errorReporter=errPipe);</pre><pre>always @(consumer.popevent) consumer.data = fifo.pop();</pre><pre>always @(producer.pushevent)fifo.push(producer.data);</pre><p>The designer only thinks in concepts of consumer and producer objects, and the FIFO semantics (to which these objects comply). There is no need to think about driving or sampling signals. The <em>Fifo</em> object uses an error/exception signaling layer which is bound to a specific chip-level error-reporting object/module (<em>errPipe</em>). The <em>ErrPipe</em> interface may contain methods and events.</p><h3>Unnecessary Ambiguity and Translation</h3><p>As previously described, no matter the amount of hierarchical “bundling” of RTL constructs, the abstraction is always the same, save for some conceptual abstraction which exists in the head of the designer and hopefully in a micro-architectural document as text. Below is a diagram which shows these processes between a designer and verification engineer in an RTL abstraction flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AdiMHXZ05q5YRy2nDAZmtw.png" /><figcaption>Drawing by Sebastian Ahmed</figcaption></figure><p>Despite all the great power that verification engineers have at their disposal today with UVM and SystemVerilog, they cannot escape the highlighted processes shown in the diagram above.</p><p>The original higher-level design-intent (concepts) is essentially <strong>lost in translation </strong>when the designer writes the RTL. Typically, such concepts are also generated <em>during</em> the design process and directly translated to RTL. Well written micro-architectural documents, despite being very helpful do not provide any programmatical way to convey the concepts. Each time the RTL is inspected, modified or debugged, it must be re-comprehended into the higher-level intent.</p><p>The verification engineer starts with whatever paper specification is available and from there, iterates on connecting the paper-specification concepts to whatever implicit concepts are buried in the RTL.</p><blockquote>This can be a tedious process full of vagaries with no common semantic framework to align on.</blockquote><p>Also, consider the task of code-coverage. The verification engineer must steer the verification stimulus which may be based on higher-level concepts to try and hit coverage on code for which there does not exist any abstract equivalent. The verification engineer is thus expending effort on verifying things that are truly below the design-intent, which the designer themselves only used because there was no facility to directly codify the intended higher-level abstraction in the first place.</p><p>The goal of a higher-level design language is not necessarily to remove the middle layers, but to significantly reduce them. As such, it should be obvious, even intuitively so, how much effort this may save on any silicon or FPGA design project. It should also be intuitively obvious that such low-level code is harder to maintain and extend.</p><h3>Inheritance and Polymorphism</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n8HZ3cpFFhOflwLZNBXHvg.jpeg" /><figcaption>Photo and code by Sebastian Ahmed</figcaption></figure><p>Abstraction truly shows its power once there is a desire to <strong>modify or extend</strong> something. We will now switch to Python because I want to be able to show a working example of how modifying or extending a design with a more abstract design-intent might look.</p><p>First let us start with an abstraction of a FIFO written in Python. An abstraction can be found here:</p><pre><a href="https://github.com/sebastian-ahmed/fifo_tools/blob/main/fifo_pkg/Fifo.py">https://github.com/sebastian-ahmed/fifo_tools/blob/main/fifo_pkg/Fifo.py</a></pre><p>This FIFO is almost a pure abstraction because it does not even support any provision for storing data. The reason is that this is a model for the purposes of architectural simulation where the intent is to simulate the size of the FIFO and the data storage is irrelevant.</p><p>For the sake of illustration however, let us assume that this is some sort of FIFO design base class. It provides the basic interface and facilities such as level and error detection and reporting. As a designer, we wish to extend this base class to create a FIFO that is more useful. At the very least we wish to add data-storage capability.</p><p>An example extension to the <em>Fifo</em> class is <em>BetterFifo</em>, which can be found here:</p><pre><a href="https://github.com/sebastian-ahmed/fifo_tools/blob/main/extension.py">https://github.com/sebastian-ahmed/fifo_tools/blob/main/extension.py</a></pre><p>Some important things about this design extension:</p><ul><li>This was more than an exercise in abstraction. I also introduced Object-Oriented Programming (OOP) concepts here such as <strong>inheritance</strong> allowing us to <strong>extend</strong> an existing design without modifying it and <strong>polymorphism</strong> by overriding the <em>push()</em> and <em>pop()</em> interface methods and extending semantics with <em>bulk_pop()</em>.</li><li>We maintained the semantics of a <em>Fifo</em>, so code which previously used <em>Fifo</em> could use <em>BetterFifo</em> and at the very least get the improved <em>bwratio</em> property which handles the divide-by-zero exception.</li><li>The storage element uses a natively supported Python list which is a <em>sequence type</em>. A higher-level HDL for design should allow direct usage of similar types such as <strong>queues</strong>. There is no reason why native types such as queues should not be available for the design subset.</li><li>Code-reviews, coverage and testing of <em>BetterFifo</em> only needs to focus on the class extension code. Likely, the test-suite for the <em>Fifo</em> base-class can also be re-used and perhaps itself extended if it was organized in an OOP way</li></ul><blockquote>There is no need to re-verify the Fifo design, because we did not change a line of code</blockquote><h3>C++ and High-Level Synthesis</h3><p>It is now time to talk about C++. It is well known that there is support and usage of C++ based design-entry (including the synthesizable subset of the SystemC standard). This class of design-intent and tooling is known as <strong>“High-Level Synthesis”</strong> (HLS for short). After more than 25 years since Verilog was created, why isn’t every silicon designer and FPGA engineer using C++ HLS exclusively?</p><ul><li>Much like C is still alive and strong today (especially in embedded systems and OS kernels), the <strong>need for RTL abstraction has not gone away</strong> and HLS has not obviated the complete need for it. There will always be a class of circuits that need to reflect low-level design semantics. Examples might be clock circuitry, reset controllers, ultra low-power circuits, power management controllers and efficient general-purpose processor design.</li><li>C++ is not a Domain Specific Language (DSL). As such, even though it provides tremendous benefits in terms of re-using algorithmic models or plugging into a C++ based software virtual platform, the syntax becomes clumsy when trying to describe hardware semantics (such as concurrency, not be confused with <em>pthreads</em>). Many traditional RTL designers face a very <strong>steep learning curve</strong> to become comfortable with developing in C++.</li><li>Sub-system and chip-level simulations are still grounded in the Verilog HDL simulator. This means that the C++ models cannot be easily modified or debugged in the context of such a simulation. C++ is also not a verification DSL. This means that one must still rely on a Verilog simulator and expertise to perform the serious verification (such as coverage driven random, temporal assertions and formal).</li></ul><p>That being said, for teams who know their way around C++ and situations where there are opportunities to directly re-use existing C++ code, there will always be some very good reasons to leverage HLS.</p><h3>A Practical Path Forward</h3><p>Getting to a truly ubiquitous multi-abstraction, multi-paradigm high-level design HDL solution needs to follow the approach of the <strong>verification</strong> <strong>subset</strong> of SystemVerilog which brought concepts from past verification DSLs such as <em>e</em> and general-purpose OOP dynamic languages such as Java into the existing Verilog language. This provided verification engineers with all the powerful tools they needed to describe verification constructs with higher-level semantics but within a backwards compatible <strong>unified language and simulator</strong>.</p><blockquote>The SystemVerilog for verification experience has proven that maintaining legacy (with all its low-level abstractions) is the method by which a smooth transition and up leveling can occur.</blockquote><p>The same must happen with design. A <strong>new version of SystemVerilog</strong> must address the grossly lacking support for higher-level abstraction and OOP paradigms. This would be in addition to all the existing legacy abstractions down to switch-level constructs. We would see a steady progression of the higher-level abstractions in designs which do not require or benefit from low-level design-intent. All abstractions would co-exist within the same development environment, tools and simulator.</p><p>Such a language must continue to be an <strong>industry standard</strong> (IEEE ratified) and ideally come with reference simulators and synthesis tools. Proprietary extensions and libraries should never be mandatory. Commercial EDA vendors could differentiate with <strong>optional libraries</strong> and extensions as well as providing the best developer experience for debugging.</p><h3>How would such a future look?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZJf5WVbPDPwvqI7m5Y7twQ.jpeg" /><figcaption>Photo by Sebastian Ahmed (Hinterland, Queensland Australia)</figcaption></figure><p>Access to a higher-level HDL by way of a SystemVerilog-for-design evolution, would bring about massive increases in efficiency and a paradigm shift in design re-use leading to better optimized and more innovative designs.</p><ul><li>Both verification and design would benefit from programmatically defined higher-level concepts which could be shared in a common library. For larger and more complex designs, this could represent multi-fold increases in productivity and efficiency. There would be a reduction in the space of verification across the board including code reviews, static code analysis, coverage, assertions, debugging and of course the removal of many translation layers as described earlier.</li><li>Design re-use today is a very monolithic and binary process. It is really an all or nothing deal. If the IP needs to be extended or modified in any way, this changes the nature of the project completely. In the case of commercially licensed IP, you may not even have the rights to modify it (and there are good reasons, such as warranties)</li></ul><p>The first point is perhaps the obvious one, the second needs a little more unpacking. As an IP provider (either internal to a chip company or as a commercial IP vendor), you do not want your users/customers to modify the IP because it would require a support model that now incorporates all the IP verification infrastructure.</p><p>Consider an IP written in this more evolved SystemVerilog-for-design which supports the standard OOP features such as inheritance and polymorphism. It would now be possible to provide a second use-case for the IP, one which provides a limited modification capability:</p><ul><li>Mandatory configuration options could be implemented via pure virtual functions. These could be behavioral configurations beyond mere parameter or tick-define settings.</li><li>Modifiable implementations can be made available via virtual functions. This allows the IP provider to precisely control what can and can’t be modified.</li><li>Extension would come naturally through inheritance, including use of the public interface to compose new extensions.</li><li>A reduced “interface-only” test-suite would be provided which also has extensible and overridable classes and methods. The extensibility would match the design extensibility interface.</li></ul><p>Extensions to an IP would thus never involve touching the base-IP by the user/customer, yet still provide them the freedom to customize, modify and extend the IP in a very controlled way which requires no modification of what is delivered by the provider.</p><blockquote>This approach would provide opportunities to innovate even in the context of re-use.</blockquote><p>This is a really important point, because in silicon, the binary nature of re-use means that when re-using IP, it is a decision to not innovate on any level within the scope of that IP. This is completely unnecessary and quite limiting for innovation and frankly in stark contrast to how OOP has enabled derivation-based innovation in the software world.</p><p>Commercial IP providers could always charge a slightly higher licensing or support-and-maintenance cost for the “extensible” interface even to the point of providing multiple tiers of extensibility via appropriately enabled virtual interfaces.</p><h3>Summary</h3><p>After over <strong>twenty years of evolution</strong>, the industry de-facto HDL, Verilog has only incrementally improved in its design subset facilities. In comparison, the verification and behavioral modeling aspects, adopted modern programming paradigms over a decade ago based on verification domain-specific languages (DSLs) that had been around for over a decade prior.</p><p>C++ based high-level synthesis will continue to gain traction in certain applications and when coupled with engineers having the requisite skillset. Ubiquity in use of high-level HDLs however cannot happen until the design subset of SystemVerilog evolves to bring <strong>OOP concepts</strong> and advanced programming paradigms which can primarily be based on the existing verification subset.</p><p>Once SystemVerilog-for-design adds this support, there will be a revolution in the scaling and innovation in silicon design because not only will designers operate at the appropriate level to match <em>design-intent</em>, but because their partner verification teams will no longer be carting around unnecessary abstraction translation layers which are major sources of <strong>technical friction</strong>.</p><p>The surprise benefit and a big opportunity for the silicon industry is how</p><blockquote>design re-use may no longer need to be a binary decision of re-use vs innovation.</blockquote><p>Both concepts of re-use and innovation will exist <strong>concurrently</strong> which will provide the conditions to not only expand the innovation surface of chip designs but result in better products for consumers and society.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4291bb3b94fb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/how-silicon-innovation-could-massively-scale-with-more-abstraction-4291bb3b94fb">How Silicon Innovation Could Massively Scale With More Abstraction</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to “fail fast and fail often”]]></title>
            <link>https://medium.com/swlh/how-to-fail-fast-and-fail-often-b55f6866d290?source=rss-2692d6a677fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/b55f6866d290</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[process-improvement]]></category>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[fail-fast]]></category>
            <dc:creator><![CDATA[Sebastian Ahmed]]></dc:creator>
            <pubDate>Fri, 15 Jan 2021 03:07:39 GMT</pubDate>
            <atom:updated>2021-01-18T02:08:07.526Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hNtOsB7mr_QMCwcq4ZE2JQ.jpeg" /><figcaption>Photo by Sebastian Ahmed</figcaption></figure><h3>Introduction</h3><p>In this article I describe how this seemingly provocative concept is actually a template for <strong>up-leveling</strong> development to attain high-velocity and <strong>efficient use of people-time</strong>.</p><p>Although this concept can be applied to any phase of development, I focus on the front-end phases which define <strong>architectures</strong> and the <strong>direction</strong> for development because this is the phase which has the most <strong>impact on downstream teams</strong>. I will show that although this is a powerful paradigm, the requisite capabilities are not trivial and need to be grown and developed.</p><h3>Not really Failure</h3><p>If Thomas Edison “failed” 10,000 times so he can “succeed” once in taming incandescence, it would suggest that even a great inventor with copious amounts of grit is “failing” most of the time. The reality is that none of these were true failures. These were just steps in the process of his relatively expedient two-year journey.</p><p>If such failures are merely steps in a sequence to reach success, then what constitutes a true failure?</p><blockquote>True failure is a determination of a result which did not meet a desire within a required timeframe.</blockquote><p>The determination of failure is made by a beholder, which could be you, your manager, a customer, the market, or even society. Had Edison taken another year to invent a production-quality bulb and no other competitor had beat him to it, Edison would have still succeeded. <strong>Success is thus time-bound</strong>.</p><p>The phrase “fail fast and fail often” is of course an <em>idiom</em> that suggests a way of innovating and developing which ironically intends to avert true failure altogether because timely success is still the goal. Failure, by the idiomatic sense simply constitutes a <em>measurable outcome</em>.</p><h3>Failing Fast … and efficiently</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*7meF8Tw1SbLU0bSUX3oTig.jpeg" /></figure><p>Failing fast is really about the ability to explore a design space by iteration in an efficient and sufficiently expedient manner.</p><p><strong>Sufficiently expedient</strong> is a function of how <em>often</em> one fails in relation to the time-bound constraint. Edison was an incredibly fast iterator. He had his own glass blowing shed and had a steady stream of suppliers around the world who systematically sent him materials to test as candidate filaments.</p><p><strong>Efficiency</strong> is about doing something with little waste and utilizing few resources. This is where the Edison analogies end because</p><blockquote>a reliable measurable outcome should require a fraction of the total time and effort required to manifest the product.</blockquote><p>The “product” here constitutes your deliverable, not necessarily the final end-product.</p><p>Teams which fail the fastest, have the following capabilities:</p><ul><li><strong>Experienced optimists</strong> who open more doors than they close. This is first line of defense and opportunity where most of the failures should occur. Highly experienced innovators have effective “<strong>brain simulators</strong>” that are just as capable of seeing an opportunity as identifying paths laden with peril. An experienced optimist might say things like “<em>yes, we tried something like that five years ago. It failed, but some assumptions have changed, so go ahead and see where it takes you</em>”.</li><li><strong>Abstract models</strong> and <strong>prototyping</strong> environments which provide useful insights, <strong>quickly</strong>. Usually developed and simulated by a small team. This is the second line of defense. Many failures can and should also occur in this loop. A good example of this is the use of <em>virtual platforms</em> and high-level models for embedded systems.</li><li>Front-loaded “<strong>canaries in the coal mine</strong>” during development which can predict undesired outcomes early in the process. This is the last line of defense which may require resetting the development loop back into the prototyping loop. These “canaries” usually require a “shift-left” methodology where initial designs can be vetted earlier in the development phase. An example “canary” could involve test-driven development.</li></ul><p>It should be noted, that</p><blockquote>nothing here requires rushing, reducing quality, cutting corners, removing features, thrashing around, or working your team to burnout.</blockquote><p>It is about working “smart”, by <strong>up leveling</strong> the capture and simulation of <em>design-intent</em> while dealing with well understood randomness up-front. This is no simple feat and requires <strong>building a team</strong> that can attain this level of capability. It is thus an investment.</p><h3>Failing Often … but with direction</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*vJU5z6_gG9yblj94MHCxwA.jpeg" /></figure><p>Minimizing <em>mean-time-to-failure</em> alone is not sufficient however:</p><ul><li>The cumulative time of failures must be within the desired timeframe to avoid a <em>true failure</em>.</li><li>The path of failures towards the successful outcome must be <strong>self-guiding</strong> with an <strong>overarching directive</strong> which can manifest itself in the early iterations.</li></ul><p>The first point is rather obvious. The second point is the less obvious aspect.</p><p>To illustrate this point, consider machine-learning, and more specifically neural networks. Neural networks are perhaps the most ubiquitous types of machine-learning structures today. A common type of neural network is a classifier which is trained with examples. Consider a classifier for images such as “dog”, “cat”, “plane” and so on. How does such a network get trained to perform classifications reliably and with new data it has never seen before?</p><p>The <strong>training </strong>of a neural network involves a systematically controlled steering of a “direction” towards the <strong>objective</strong> of correctness. Throughout the training sequences, the optimizer is “failing” towards the solution by way of measuring the <em>gradient</em> of convergence towards correctness in relation to the network parameters. This is important, because in theory, training a neural network could be an incredibly exhaustive exercise even for the simplest network. The optimizer essentially has a <strong>guiding compass</strong> that tells it whether it is moving towards the objective or not. This is an <strong>abstraction</strong> (and a <strong>noisy</strong> one at that), and that is ok.</p><p>Models, abstractions and early “canaries in the coal mine” are all somewhat <strong>random processes</strong>. They do not provide a definitive measure of success and so for these early iterations to be indicative of true failure (or success) further downstream,</p><blockquote>these models must provide not only whether the outcome is a pass or fail, but more so they must indicate a direction to take for the next iteration.</blockquote><p>Without such a <strong>compass</strong>, you will run out of tries, because you can only fail so often for any given project before reaching “true failure”. What such a compass constitutes depends on the problem at hand, but <em>telemetry</em> and intelligent processing thereof, is a generally great pattern to gain inspiration from.</p><h3>Succeeding fast and succeeding often</h3><p>Failing fast and failing often requires capabilities, and purpose in people and the development process with a <strong>bias towards early prototyping</strong> which is fast, provides a sufficiently reliable measurable outcome, and requires exposing the churn to fewer people. Fewer people and shorter periods of time means efficiency.</p><p>Each iteration should provide new information to <strong>remove randomness</strong> from the process and provide a <strong>direction or hint</strong> for the next iteration thus minimizing the number of iterations required. Once established, such machinery can enable a team to experience a <strong>high-velocity</strong> and frequency of successful outcomes and a reduction in exposing larger downstream teams to paths of peril.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b55f6866d290" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/how-to-fail-fast-and-fail-often-b55f6866d290">How to “fail fast and fail often”</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unpacking Delegation — Part 5]]></title>
            <link>https://medium.com/swlh/unpacking-delegation-part-5-c1560cff0174?source=rss-2692d6a677fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1560cff0174</guid>
            <category><![CDATA[leadership-coaching]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[delegation]]></category>
            <category><![CDATA[leadership]]></category>
            <dc:creator><![CDATA[Sebastian Ahmed]]></dc:creator>
            <pubDate>Sun, 03 Jan 2021 01:29:53 GMT</pubDate>
            <atom:updated>2021-01-05T10:04:32.284Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P1Mi7g0uYK66cVz2CBgEUg.png" /><figcaption>Photo by Sebastian Ahmed</figcaption></figure><h3>Unpacking Delegation — Part 5</h3><p>This is the final part of my series of articles about delegation for technology leaders. I would love to write more on this topic, but to do so, I need to learn more through observation and experience.</p><p>In this installment, we look at the <strong>temporal properties</strong> of delegation, followed by listing <strong>possible outcomes</strong> resulting from systematic delegation including the <em>busting of our final myth</em><strong> </strong>and close out with a more <strong>formalized definition</strong> of delegation.</p><h3>Temporal Response</h3><p>The effectiveness of delegation in relation to time can be a function of many dependent variables. The benefit (or lack thereof) of delegation moves in lockstep between delegator and delegate. For example, consider the fact that after delegating you are freed to focus on the next major thing in your queue (which is a good thing), and the delegate gets to drive a high-value project that is also important to them (which is also good). On the other hand, if you hold on to the “thing”, progress will slow and the thing may lose relevance or suffer. At the same time, your team will be missing out on a great opportunity and possibly observing your failure (bad for everyone involved).</p><p>A conceptual view of how this “win-win” or “lose-lose” affect occurs over time, can be viewed as the “effectiveness” (<strong><em>E</em></strong>) of the delegation as a function of time (<strong><em>t</em></strong>) as show in the diagram below. The temporal response is a continuous function, but we can generally split it into four <em>regions:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cwZym9stZtYo4JpqFGF-sA.png" /><figcaption>Drawing by Sebastian Ahmed</figcaption></figure><h4>The Region of Uncertainty</h4><p>During this time, the “thing” is a very new idea or initiative. It is not at all clear what the goals are, the possible outcomes or if it is even worth doing. Delegating something so early in the process will result in a possibly random effectiveness (and possibly <em>frustrating </em>for both parties). This region of time should represent the very <strong>fuzzy front-end</strong> of the “thing” and is probably best left to evolve further.</p><h4>The Regions of Opportunity and Decay</h4><p>In these two regions, (which I am grouping together because they form a continuum) is where the delegation will have the most effect. It is early enough that it provides opportunity for the delegate to determine its strategy (<strong>true ownership</strong> involves autonomy in <strong>shaping the project</strong>) and enables you to go into the influencing/supporting role.</p><p>How does one know they are in this region? Some signs would be:</p><ul><li>Clarity in relation to the region “Region of Uncertainty” in terms of what the project is in terms of goals and scope. At this point there should actionable things to really move forward (plans, people).</li><li>Overall it should feel like something that one of your team members can take from here with some initial guidance. The level of uncertainty and complexity will of course be different if you are delegating to an emerging technical lead vs a senior manager. In the latter, the “thing” should be something that is approaching director-level responsibilities.</li></ul><p>If you are a new manager for example, you may wonder how do you go about delegating during this region. There may be confusion whether it is in fact your responsibility as a leader to delegate this “thing”. Ask yourself this question:</p><blockquote>“is there someone on my team that will benefit and grow more than I, if I delegate?”</blockquote><p>If the answer is yes, then you should delegate this. The reason is twofold, 1) That person will grow and 2) You can seek a “thing” that will help you grow to lead better. If the answer is no, it may be a sign that this “thing” may be an unreasonable thing to delegate and it is important you use it as an opportunity to develop your abilities.</p><p>As we enter the “Region of Decay”, what has likely happened is that you have spent too much energy on the “thing”. You may even feel like you are slowing things down a bit. The delegate may feel a slight sense of a half-baked project being handed to them and possible concerns about having enough room to shape it in the right way. But it is still “all good” at this point.</p><h4>The Region of Damage</h4><p>Note the cliff which is formed by the transition from the “Region of Decay”. This is essentially the region of a <strong>failed delegation</strong>. Damage has been done to both the delegator and delegate. You as the delegator held on to the “thing” for too long. It has possibly cost you in terms of other more strategic things (<em>opportunity cost</em>) and the “thing” itself is likely suffering. Now you are truly <strong>dumping this failure</strong> on someone else. They will be under pressure to salvage the thing with limited opportunity to do it right.</p><blockquote>If you are in the region of damage, you may consider abandoning the thing, because “nothing gained” may better than “damage done”.</blockquote><p>How do you know you are in this region? Here are the signs:</p><ul><li>You had no serious intent to delegate this thing and you are likely failing at leading it, because you did not have the time and focus or possibly even lack some required skills or experience.</li><li>Your delegation may only provide diminished benefits for the delegate such as growth at this point. The opportunities to shape the thing are not really there.</li><li>Overall, a delegation attempt in this time region looks and feels more like a call to save the day rather than a more noble desire to provide opportunity.</li></ul><p>If you have no choice but to still make the “thing” happen, make sure you talk to the delegate about how you have failed on this and how you need their help. Do not try to sell it as a legitimate empowering delegation. That would be disingenuous. <strong>Always own your mistakes</strong>, learn and do better next time. This is an opportunity for showing some humility.</p><p>It may be noted that such a curve may also apply to making timely decisions (a topic for another post).</p><h3>So that innovation and people can thrive</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yVxJL4ROss9EAqZPMGTsmA.jpeg" /><figcaption>Photo by Sebastian Ahmed (a thriving forest in Flagstaff, AZ)</figcaption></figure><p>The title of this section was the “why” in my <em>user-story</em> definition of delegation covered in <a href="https://sebastian-ahmed.medium.com/unpacking-delegation-part-1-71d3d9d8b141">Part 1</a>. In this section, we provide some possible outcomes around innovation, people, and team culture resulting from effective delegation. This is by no means a complete list, but rather a sampling of possible outcomes that may resonate with you:</p><ul><li>Your team sees you as someone who has their careers and ambitions at the forefront of your mind. This is safety and trust.</li><li>The team is more energetic, productive, and engaged. The sense of mission and vision is strong.</li><li>You spend more time on exploring new ideas and seeing the forest from the trees ensuring that the overall team is moving towards the vision.</li><li>You have been able to get more in-depth technically on a variety of new technologies, some of which may lead to driving new initiatives you will delegate in the future — thus <strong>crushing Myth #4</strong>: <em>“Delegation will erode my ‘currency’ as a technical expert”</em></li><li>The “stagnant” team (described in <a href="https://sebastian-ahmed.medium.com/unpacking-delegation-part-4-c25f81c705b0">Part 4</a>) gets involved with an exciting new project breathing some new life and excitement into their mission.</li><li>You find you have a lot more time for regular one-on-ones which are your most important meetings by far.</li></ul><p>What are some other possible outcomes that you can think of? The outcomes you can think of should be the reasons to delegate.</p><h3>Summary</h3><p>It is my hope that that you have gained some new perspective on what it really means to delegate resulting in a successful <em>unpacking</em>. In closing, I will leave you with my more formal definition of delegation:</p><blockquote>Delegation is a process which provides the required agency for ideas to give rise to outcomes that create new value in people, teams, and innovation.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1560cff0174" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/unpacking-delegation-part-5-c1560cff0174">Unpacking Delegation — Part 5</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Primer on Sizing Hardware FIFOs]]></title>
            <link>https://medium.com/swlh/a-primer-on-sizing-hardware-fifos-c1db97b9a25e?source=rss-2692d6a677fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1db97b9a25e</guid>
            <category><![CDATA[fifo]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[simulator]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[silicon]]></category>
            <dc:creator><![CDATA[Sebastian Ahmed]]></dc:creator>
            <pubDate>Sat, 02 Jan 2021 17:23:11 GMT</pubDate>
            <atom:updated>2021-01-22T00:41:15.737Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*lWMGgLT8RVbGeuhieRPawA.png" /></figure><p>FIFOs (First-In, First-Out) are point-to-point elastic storage elements that are very commonly used in embedded systems to pass data across an asynchronous interface in a very efficient manner. In this context, <em>asynchronous</em> simply means that the two ends of the FIFO are behaving independently save for some initial signaling to initiate a transfer.</p><p>A typical question that silicon or FPGA architects are often faced with is how big should they make a FIFO? In this article, we will cover the theory, the practice and an easy-to-use <a href="https://github.com/sebastian-ahmed/fifo_tools"><strong>open-source Python simulator</strong></a> you can use to experiment with scenarios in order to answer this question in a systematic way.</p><h3>The Theory</h3><p>FIFOs have two ports, a read port and a write port. The write port <strong>pushes</strong> data into the FIFO and the read port <strong>pops</strong> data from the FIFO. This is a simple <em>consumer/producer </em>pattern.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uYRXbWy06t9T-bqOuZjRfw.png" /><figcaption>Drawing by Sebastian Ahmed</figcaption></figure><p>The FIFO has three main purposes:</p><ul><li>Provide sufficient storage to account for the production/consumption rate differences between the read and write domains over a <strong>finite transfer size</strong></li><li>Provide sufficient storage to absorb <strong>short term fluctuations</strong> (such as bursts/stalls) between the two domains</li><li>Account for <strong>startup latencies</strong> associated around the start of the read domain relative to the write domain operations</li></ul><p>The first point is the primary factor in determining the size. The second point is a peak versus average concept and may end up being the factor which determines the size. The third point relates to the low-level implementation details of the FIFO controller and latencies associated with initiating the read port domain after the write port domain has signaled its readiness.</p><p>Let us focus on the primary aspect first. Consider the producer/consumer bandwidths of the read and write ports expressed as relative values.</p><ul><li>A write bandwidth BW(write)</li><li>A read bandwidth BW(read)</li></ul><p>The units are not important (e.g., MB/second). It is simply a rate in normalized units of <strong>transfers per unit time</strong>. All that matters is that the read and write bandwidths are in the same units.</p><p>Now, let us consider a finite transfer size as the <em>payload </em>expressed in the units of the minimum transfer size. We can refer to this as PL(size). The formulaic approach to determine the required FIFO size based on these three parameters is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UqLHG4glSxpGvJLkpdouWQ.png" /><figcaption>Equation by Sebastian Ahmed</figcaption></figure><p>This is a relatively straightforward rate-ratio calculation and follows the simplest queueing theory where both the item sequence (producer) and server (consumer) follow fixed rates. Here we perform the calculation from either the read or write port perspective and pick the worst case scenario.</p><ul><li>In the case where BW(write) &gt; BW(read), we need a FIFO large enough to capture the accumulation of data that occurs over the PL(size) interval. This accumulation rate is BW(write)-BW(read)</li><li>In the case where BW(read) &gt; BW(write), we need the producer to buffer the full calculated FIFO size before the consumer side is initiated. The contents will drain at a rate defined by BW(read)-BW(write) over the PL(size) interval</li></ul><p>So, we are all done, right? sort of …</p><h3>The Practice</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*4gjB6TI67PxhTQvII8Spxg.png" /><figcaption>Illustration by Sebastian Ahmed</figcaption></figure><p>How exactly do we choose the various parameters for the equation? For example, what is the payload size and what are the bandwidths?</p><p>In very simple systems, these may be completely obvious. Things get complicated when we have to consider the following system characteristics:</p><ul><li>The consumer and producer relative bandwidth ratios are not constant over time and may follow behaviors that look more like statistical distributions.</li><li>The consumer and producer experience short term fluctuations causing bursts or stalls. Each side may be subject to variations in short term throughput due to access of a shared memory sub-system.</li><li>The payload size is very large or <em>infinite</em>. This can occur in display pipelines for example, which for all intents and purposes can have <em>infinitely </em>sized payloads.</li></ul><p>It turns out that the previous equation still holds true, with the caveat that we now need to analyze multiple solutions of this equation to comprehend the different scenarios. Besides the <strong>average bandwidths</strong> which are defined over the PL(size) interval, we also need to consider <strong>peak bandwidths</strong> over a <em>subset of the interval</em>.</p><p>To illustrate this distinction, consider a system where the consumer and producer bandwidths are equal. This would suggest a FIFO size of zero, but it is doubtful that this would work in practice. All it would take is a few stall cycles on a bus somewhere in the producer or consumer domain, to require a few entries. Here, the peak case (temporary stalls) determines the FIFO size.</p><p>Lastly, there is some accounting required in relation to the specific implementation of a given FIFO controller, especially when dealing with FIFOs which cross hardware clocking domains (known as <em>asynchronous FIFOs</em>). It is beyond the scope of this article to get into these details, but typical implementations may require several clocks worth of uncertainty that need to be considered.</p><h3>The Simulation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tCbtfcp5MCxslJMxcalnvg.jpeg" /><figcaption>Photo and code by Sebastian Ahmed</figcaption></figure><p>Using the formulaic approach is a necessary step, but engineers are pragmatic humans that like to see things working, and there is nothing more pragmatic than simulation. Also, for the cases where the bandwidths are not constant-rate, a <em>random variable</em> from a <strong>discrete statistical distribution</strong> model must be used.</p><p>Typically, simulations for hardware are done in an HDL simulator at the RTL abstraction level. In my mind, this is a downstream step, and initial architectural work requires a simpler approach where the design space can be explored quickly. This is typically done in a high-level modeling environment (such as <em>SystemC</em>), but for the purposes of a simpler demonstration I wrote a basic<strong> open-source FIFO simulator in Python </strong>which does leverage a random variable to generate consumer and producer rates.</p><p>The value of a simulation is that it can model short term behaviors with randomness.</p><blockquote>Randomness provides a check and balance to the formulaic approach.</blockquote><p>The simulator can be found here with full details on how to run it:</p><p><a href="https://github.com/sebastian-ahmed/fifo_tools">https://github.com/sebastian-ahmed/fifo_tools</a></p><p>The simulator also provides the formulaic calculation (which can be run independently of the simulation step)</p><p>The simulator is quite simple, with the following mechanics that are worth noting:</p><ul><li>The consumer and producer are run as independent <strong>threads</strong> operating on a shared thread-safe FIFO object via a <strong>simulation kernel thread</strong> which manages a simulation event queue with a configurable <em>quantum</em>. The quantum allows control of simulation speed vs short-term accuracy.</li><li>The <em>effective</em> average bandwidth ratio is based on a<strong> </strong><em>desired</em><strong> </strong>statistical distribution configured from the input read and write bandwidths. The simulator uses a <strong>binomial</strong> <strong>distribution</strong> with a single trial and a <em>target probability</em> of push or pop operations being a function of bandwidths.</li></ul><p>Since the operations of the consumer and producer threads are based on sampling a random number generator source with a target statistical distribution,</p><blockquote>the resultant bandwidth ratio is never perfect, and this is a good thing.</blockquote><p>When running the simulator a few things to note:</p><ul><li>When BW(read) &gt; BW(write), the <em>initlevel</em> parameter should be set appropriately to a level that is at the target level of the FIFO</li><li>When BW(write) &gt; BW(read), always set an <em>initlevel </em>greater than the default(1). This is because of the randomness of the producer/consumer threads in a short interval will usually look like complete noise relative to the average bandwidth ratio. As such, <em>underrun</em> errors may occur during the simulation</li><li>Running with the <em>verbose</em> option shows all FIFO operations in real-time</li><li>The simulator is better suited to modeling larger payloads because the random distribution becomes more accurate over a larger sample set</li></ul><p>Below is a screen capture of running the simulator in a shell:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*OAzT7akv6-_HTHm5aEIMhQ.png" /><figcaption>Example output of the simulator</figcaption></figure><p>Note how the formulaic approach yielded a depth of 91 and in the simulation, a peak level of 114 was hit. Part of this is because an initial level of 16 entries was configured, but it also reflects short term noise in the read/write ratio bandwidth which the formulaic approach cannot reflect.</p><h3>Summary</h3><ul><li>The initial sizing of hardware FIFOs can be done in a formulaic way as long as the consumer/producer systems can be described for the appropriate scenarios for both <strong>average</strong> and <strong>peak</strong> situations.</li><li>Simulation with <strong>random variation </strong>within a<strong> statistical distribution </strong>will provide further insights in order to check formulaic approach. Although a relatively simple simulator has been provided as part of this article there are far more advanced high-level modeling techniques.</li><li>Each FIFO controller design is different, and for smaller FIFOs, some of the low-level uncertainties and latencies must be accounted for in the sizing.</li><li>The final proof is always in the pudding of a system-level RTL-based simulation, but it helps to have a high-confidence first target to avoid thrashing in the design space.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1db97b9a25e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/a-primer-on-sizing-hardware-fifos-c1db97b9a25e">A Primer on Sizing Hardware FIFOs</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Challenges and opportunities for open-source in Silicon — Part 5]]></title>
            <link>https://medium.com/swlh/challenges-and-opportunities-for-open-source-in-silicon-part-5-202ce0e32a12?source=rss-2692d6a677fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/202ce0e32a12</guid>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[silicon]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[opensource-hardware]]></category>
            <dc:creator><![CDATA[Sebastian Ahmed]]></dc:creator>
            <pubDate>Thu, 31 Dec 2020 01:56:18 GMT</pubDate>
            <atom:updated>2021-01-15T19:55:49.020Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WrCK7Y6n8WfeoG5eIRqkQA.jpeg" /><figcaption>Picture by Sebastian Ahmed (Alcatraz Island, San Francisco)</figcaption></figure><h3>Challenges and opportunities for open-source in Silicon — Part 5</h3><p>Continuing with the theme of the big opportunities started in <a href="https://sebastian-ahmed.medium.com/challenges-and-opportunities-for-open-source-in-silicon-part-4-db70e7e7d79">Part 4</a> where we discussed the potential benefits of an open-source RISC ISA, in this installment, we look at how <strong>embedded security</strong> may benefit from open-source approaches</p><p>Embedded security is no longer the realm of specialized chips or markets (such as banking or military). These days, any general purpose microcontroller or application processor needs to provide security supporting not just application-level security (such as required by communications protocols), but also secure boot, secure key storage and beyond.</p><blockquote>Security in general, is a never-ending process.</blockquote><p>It is a process because it is stateful and ever-changing. There is no such thing as absolute security and the ways in which security can be compromised continues to surprise us. For example, low-level cryptographic primitives such as AES despite being mathematically intractable, were easily overcome with side-channel analysis. Long-standing processor micro-architecture approaches were eventually found to leak secrets via software-based attacks as demonstrated by the <em>Meltdown </em>and <em>Spectre </em>bugs.</p><h3>Security through transparency</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S4DQueoKw-KjdLqjP4uXCQ.jpeg" /><figcaption>Photo by Sebastian Ahmed (source-code credit: OpenTitan, Apache 2.0)</figcaption></figure><p>Does open-source silicon hardware and associated firmware make things less or more secure? When it comes to security, there is never a definitive answer. But it is worth to consider some of the properties of open-source that may provide significant value in security.</p><blockquote>“Given enough eyeballs, all bugs are shallow” — Linus’ Law</blockquote><p>In hindsight, every security flaw is indeed a bug. Whether it is an implementation flaw, an architectural flaw or a fundamental algorithmic flaw, they are all bugs. We thus go back to the concept of the value of “many eyeballs”. The more eyes on the problem, the better. As we discussed in <a href="https://sebastian-ahmed.medium.com/challenges-and-opportunities-for-open-source-in-silicon-part-3-e485837d17ce">Part 3</a>, there is no place to hide for bad decisions and poor implementations, so the level of scrutiny is unbound and continually evolving.</p><p>In closed-source implementations you are likely at the mercy of a small team of developers whose priorities and possibly competency-level can shift over time. There is no such thing as absolute security, so the way in which <em>secureness</em> is measured, is a never-ending process. It is thus possible that such an unbound problem is not well suited to be solved by so few. Note, that this is not a statement of governance, but eyeballs (transparency and number of testers).</p><p>So a key question to ask is whether hiding implementation details is a form of security. This author’s opinion is that nothing is further from the truth, and so</p><blockquote>“Security through obscurity” is a dangerous fallacy</blockquote><p>This notion was first introduced by 19th century Dutch cryptographer Auguste Kerckhoffs:</p><blockquote>“A cryptosystem should be secure even if everything about the system, except the key, is public knowledge.” — <a href="https://en.wikipedia.org/wiki/Auguste_Kerckhoffs">Auguste Kerckhoffs</a></blockquote><ul><li>There is no security through obscurity. This is a false premise. At best, it buys some time, but once the “secret is out”, there is no remedy. More so, it falsely <em>reduces the burden</em> on the developers to make the solution inherently secure. A “false sense of security” as it were, <strong>reduces incentives to do things right</strong>.</li><li><strong>Glass-box testing</strong> provides the opportunity to test and attack an implementation in a more controlled and comprehensive level. This may include a variety of approaches in simulation, FPGA emulation or even via formal proofs. This would include RTL source and firmware.</li><li>Exposing implementation details, <strong>accelerates both the</strong> <strong>ethical and non-ethical hackers</strong>’ ability to find vulnerabilities. This obviously requires the attention and competence of ethical hackers much more so than un-ethical hackers, but even un-ethical hackers may not be able to resist exposing their finds.</li></ul><p>When it comes to glass-box testing in particular, the gamut of tools and approaches is so broad, that no one enterprise can do all these things well. The potential benefit of open-source is that it could allows experts in various domains and with access to specialized skillsets, tools or compute resources to provide a continuum and perpetuity of testing that is never limited by any one group or enterprise.</p><h3>Timeliness and frequency of iterations</h3><p>Consider the lifecycle of a silicon-level security flaw — from creation to observation. The flaw is typically designed in at the module-level IP development stage (or even earlier, such as during the architectural stage prior to the RTL IP development).</p><p>When do we typically hear about a publicly discovered security exploit in relation to such a flaw?</p><blockquote>Flaws are usually found in and reported against an end-product, long after silicon development has completed.</blockquote><p>What happens after this? If the silicon provider is lucky, there is some low-level protected firmware that can patch this bug and hopefully such firmware is indeed patchable in the field (connected devices such as mobile phones or IoT products are good examples of having this capability). If firmware patching is not an option (either by lack of connectivity or the flaw being un-addressable by means of a firmware fix), the next step is to correct the issue on a subsequent silicon revision. Now, we are in for the long haul.</p><p>Such a loop to detect and correct what is often a “software” issue (in the sense that RTL code is a type of “software” which can be fully described and exercised through simulation or formal proofs), seems to be unnecessarily lengthy and costly.</p><p>We can thus identify two parameters which may describe the timeliness of publicly discovered exploits</p><ul><li>Time from design of flaw to detection of a flaw — this is <strong>latency</strong></li><li>Turnaround time from detection to observable correction of the flaw — this is <strong>bandwidth</strong></li></ul><p>The figure below shows how the phases and loops might look when we compare closed-source RTL versus open-source. The timelines are approximate, mostly to show the relative scales of each phase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ixel0pF5c_N-FFadkLY6aQ.png" /><figcaption>Drawing by Sebastian Ahmed</figcaption></figure><p>This is not a comprehensive model of reality, but it does illustrate that there is potentially, an order of magnitude delta both the latencies and bandwidths from the perspective of a constituent piece of technology (the “IP”).</p><p>No doubt, some security flaws are more physical in nature but even such flaws can exhibit hints through source-level access to an implementation.</p><blockquote>The sooner these are discovered and corrected, the better.</blockquote><p>In order to realize such benefits, the open-source approach does not require all chip-IP to be open-sourced. This is neither practical or required, but the parts that are specifically dealing with security stand to benefit from enabling the IP-level to be exposed to testers and hackers alike (the “many eyeballs”) and actually “hacked-upon” completely <strong>independent of any silicon</strong> <strong>or end-product development cycle</strong>.</p><h3>Avoiding Fragmentation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*ts0-A9qkg88MzkCS_nVDfg.png" /><figcaption>Drawing by Sebastian Ahmed</figcaption></figure><p>To successfully garner the attention of the “many eyeballs” and truly benefit from the variety and span of testing that can occur with glass-box analysis,</p><blockquote>it is important for the industry to not have too many “irons in the fire”.</blockquote><p>This suggests that the industry take a lesson from the book of RISC-V (which was discussed in <a href="https://sebastian-ahmed.medium.com/challenges-and-opportunities-for-open-source-in-silicon-part-4-db70e7e7d79">Part 4</a>). The fundamental primitives and sub-systems for embedded security (comprised of RTL hardware and firmware) need not be done in umpteen different ways or be tied to a few commercial providers.</p><p>There will always be room for innovation and proprietary solutions for some of the more specialized aspects of security, but striving towards a common base platform (which can garner those eyeballs) appears to be an <strong>opportunity for the silicon industry</strong>.</p><p>Commonality and standardization on the base elements of security could manifest through open standards. The RISC-V ISA is a good example of an open standard which is also modular. Could something similar be done for embedded security? Perhaps.</p><p>So what is going on in the landscape of open-source implementations around silicon security? A couple of noteworthy developments by some rather large companies taking public positions on open-source silicon security:</p><ul><li><strong>Google’s </strong><a href="https://opentitan.org/"><strong>OpenTitan</strong></a> project which is concerned with providing a complete silicon Root of Trust (RoT). Anyone can access and use all the RTL and software <a href="https://github.com/lowRISC/opentitan">source code</a>. It is released under an Apache 2.0 license. Notably, the main processor is based on the open-source RISC-V core which is being developed by <a href="https://www.lowrisc.org/">lowRISC</a>. Here we see the intersection of leveraging an open-source ISA as a key building block for a base security RoT.</li><li><a href="https://www.thalesgroup.com/en"><strong>Thales group</strong></a>, which is a French-based multinational with revenues of over $18B, dealing with aerospace, defense, transportation and security, announced in 2018 that they joined the RISC-V foundation with the goal to “Help Secure Open-Source Microprocessors” (<a href="https://www.thalesgroup.com/en/group/journalist/press-release/thales-joins-risc-v-foundation-help-secure-open-source">source</a>). Thales is also an active member of the OpenHW group (<a href="https://www.openhwgroup.org/membership/members/">source</a>).</li><li><strong>RISC-V</strong> in general, is ripe with security-oriented initiatives not just around the cores, but also the ecosystem of software and tools.</li></ul><h3>“As is” Basis</h3><p>Before we close out on this topic (which, by definition, is not possible since security is never “done”), it is worth discussing the caveat of open-source licenses agreements, in that such license agreements typically provide <strong>no warranties</strong> or other protections.</p><p>But just how much of a practical issue is this? Even commercially supported distributions of the Linux Kernel only provide warranties for the physical media on which the software is distributed (hardly a sufficient remedy in the case of a security breach in a data-center for example).</p><p>In order for a warranty to be have value, it must have the ability to properly remedy the cost of a security flaw which results in damages being incurred (such as a breach that may affect companies or individuals). Such protections may likely be better addressed by insurance policies.</p><h3>Summary</h3><p>Security is a massive topic, and it often seems that when one discusses or writes about it, we are left with having only scratched the proverbial surface. Nevertheless, when it comes to security, if one takes the position that <strong>transparency in the implementation</strong> has value, then open-source provides some very compelling advantages through a combination of vast opportunities for testing (in nature and volume) as well as the unique property of minimizing security flaw discovery latencies and correction bandwidths.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=202ce0e32a12" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/challenges-and-opportunities-for-open-source-in-silicon-part-5-202ce0e32a12">Challenges and opportunities for open-source in Silicon — Part 5</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Challenges and opportunities for open-source in Silicon — Part 4]]></title>
            <link>https://sebastian-ahmed.medium.com/challenges-and-opportunities-for-open-source-in-silicon-part-4-db70e7e7d79?source=rss-2692d6a677fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/db70e7e7d79</guid>
            <category><![CDATA[semiconductors]]></category>
            <category><![CDATA[silicon]]></category>
            <category><![CDATA[risc-v]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Sebastian Ahmed]]></dc:creator>
            <pubDate>Tue, 29 Dec 2020 21:12:00 GMT</pubDate>
            <atom:updated>2020-12-29T21:55:45.802Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G5xuxvRIMC6PEhQftBiLzw.jpeg" /><figcaption>Photo by Sebastian Ahmed (Sedona AZ)</figcaption></figure><h3>Challenges and opportunities for open-source in Silicon — Part 4</h3><p>In <a href="https://sebastian-ahmed.medium.com/challenges-and-opportunities-for-open-source-in-silicon-part-3-e485837d17ce">Part 3</a> we covered a lot of ground focusing on the main characteristics of open-source developments such as cost, licensing terms, governance, distributed/local development, and timing.</p><p>In this installment, we will focus squarely on what may be one of the biggest opportunities for open-source and silicon. This is the topic of the open Instruction Set Architecture (ISA), and specifically in the realm of reduced instruction set computers (RISC).</p><h3>A common computer language</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*Y5otQlNFbcbWYaXwcqur2g.gif" /><figcaption>Image Credit: Google</figcaption></figure><p>No article about open-source and silicon would be complete without discussing <strong>RISC-V</strong>. So much has been written about RISC-V that it is somewhat challenging to not cover old ground.</p><p>Let us begin with first describing what RISC-V really represents to the electronics industry (at least my current view of things):</p><blockquote>RISC-V is a pursuit towards an open, ideal, modular, and common computer language for industry, defined by industry.</blockquote><p>All programming languages are ultimately translated to a computer language. A computer language is known as the <strong>Instruction-Set Architecture</strong> (<strong>ISA</strong>). The ISA defines the lowest-level programming view of a computer (“machine”). The machine ultimately carries out the duties prescribed by the programmer. No matter what the machine does under the hood, it must maintain congruence with the ISA semantics.</p><p>The diagram below shows a simplified view of where the ISA <em>concept</em> sits in relation to machine-specific tools and the machine implementation. Here we have an ISA called “Foo”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oWJX8ka05S4NfjDSzm1UvQ.png" /><figcaption>Drawing by Sebastian Ahmed</figcaption></figure><p>As such, the ISA does not prescribe the higher-level programming language, the method of translation nor the machine implementation. It is merely a well-defined interface and a contract. When I say “well-defined”, I do not just mean in the completeness and specificity of its semantics, but that it has to be well-done (something approaching the “ideal”). The ISA tends to impact the “back-end” of compilers which deal with Register Transfer Level optimization steps and beyond (not to be confused the “RTL” of Hardware Description Languages). The “register” here refers to the ISA-visible registers.</p><p>Within the landscape of general-purpose programming languages (i.e., the languages which humans enter via keystrokes), such as C, C++, Java, Python, Julia, … the list goes on,</p><blockquote>the idea of a proprietary language is almost unheard of.</blockquote><p>In the silicon world, even the hardware description languages (HDLs) such as Verilog are open standards. Note, that having an open language does not imply open (permissive and free) or open-source tools, but it creates the right conditions to enable such things (e.g., GCC and LLVM). In fact, both can co-exist.</p><p>When it comes to ISAs however, the world has been one of proprietary specifications. This has not been a bad world, by any means. We have seen tremendous advancements across all the main computing segments including enterprise, cloud, mobile and embedded with such proprietary approaches.</p><p>It is possible however that an open ISA such as RISC-V can <strong>bring forth even more success</strong> because of its stand-alone nature allowing its use to be de-coupled from the layers above and below.</p><h3>Proprietary ISA monoliths</h3><p>Below is as diagram which shows a simplified view of how proprietary ISAs form monolithic structures consisting of machine implementations and their respective tool ports and variations. These monoliths are formed because of the proprietary nature. A proprietary ISA has a “stickiness” which congeals the machine implementation and tooling. There is no motivation to separate these in fact.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sT34ykttY-C5d4iiscZk-g.png" /><figcaption>Drawing by Sebastian Ahmed</figcaption></figure><p>There are benefits of this approach. A monolithic ISA allows complete optimization across the stack. There is no governance body to ask when coming up with a new ISA. A complete monolith is delivered each time there is an update. In fact, the machine implementation itself may act as the retroactive golden model of the ISA, which means that the ISA could be updated to reflect some nuance in the machine.</p><blockquote>The line between the ISA and the machine implementation is blurred.</blockquote><p>The first drawback to this approach, is that the ability to create monolithic stacks such as these are only afforded by a very few who can fund full-stack development including processor micro-architecture all the way to tools and optimized libraries. Yet such enterprises do not have unlimited resources and thus need to minimize the number of variants of machine implementations. This results in a limited variety and pace of evolution.</p><p>The second major drawback to this approach is related to the first in that, if a selection criterion is based on machine specifications, it may require the customer to utilize a different monolith. It is not unusual to find three or more ISA monoliths on a chip. Each monolith requires its own tools, debug, unique optimized libraries and specialized embedded developers.</p><blockquote>This is fragmentation because it involves additional resources being expended to achieve overlapping outcomes</blockquote><h3>Domain-specific architectures</h3><p>I should make clear that there is definitely plenty of space and reason for proprietary ISAs. One area is in the realm of <em>domain-specific architectures.</em> Much like domain-specific languages, these are attempting to solve specific problems in a hyper-optimized way. A good example of a domain-specific architecture is an AI neural-engine.</p><p>Typically, in such domain-specific realms, there is little benefit or motivation for the global standardization of the low-level software interface. Specialized architectures often rely on low-level controlling software (such as micro-code) which abstracts the underlying machine from what compiled software interacts with. Standardization and commonality typically occurs at higher levels of abstraction such as user APIs (e.g. TensorFlow-Lite for AI).</p><p>This does not mean that a general purpose processor cannot be specialized in its application, but even in such specialized applications, it is still a general purpose reduced instruction set computer (RISC).</p><h3>Open micro-ISAs</h3><p>Now, let us consider how things may look with an open ISA such as RISC-V, which besides being open is also modular. We could perhaps call this a micro-ISA (to borrow a term from OS microkernels which exhibit this pattern of modularity).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EnyDB4GopKDXhjtgaG-4KA.png" /><figcaption>Drawing by Sebastian Ahmed</figcaption></figure><p>Here we have something a bit different. We have made the computer language common across a variety of machines. What opportunities lie here for the silicon developers? The main opportunities appear to be related to the de-coupling effects:</p><ul><li>The software parts of the industry can focus on building the best tools and libraries for a single ISA. This is a pattern of de-fragmentation.</li><li>The “machine” implementations become efforts which completely focus on <strong>providing a variety</strong> of excellent micro-architectures for the many segments and sub-segments of the processor market. This is neither fragmentation or de-fragmentation, it is <strong>a liberation to create more value and optimization points</strong> in computer design, free from the burdens of having to deliver monolithic stacks of enablement.</li><li>When a silicon vendor or IP provider wishes to provide some <strong>specialized capability </strong>such as a <em>custom ISA extension</em>, the possibility exists to do this in an <strong>incremental </strong>way. There is no need to create a completely new ISA (to avoid license infringement or otherwise) and simply <strong>build on an established foundation</strong>.</li></ul><blockquote>This is in fact a pattern of de-fragmentation because it localizes the “fork” only to the parts that need to be forked.</blockquote><h3>Open-source ISA Implementations</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IWJbqnMv0M1JiIzkb7DnNw.png" /></figure><p>Much like the idea of open programming languages brought to fruition open-source tool-chains (which ultimately <strong>democratized programming</strong> in general), the openness of RISC-V has borne open-source implementations of the ISA.</p><p>An implementation of an ISA can span a multitude of uses and abstractions. An emulator (such as QEMU), formal model, instruction-set simulator (ISS) and silicon designs (digital RTL) all constitute implementations of an ISA.</p><p>What are the noteworthy developments in terms of actual silicon-ready RTL designs?</p><p><strong>OpenHW Group CV32E40P : </strong><em>4-stage embedded RISC-V CPU core</em></p><ul><li>Originally based on the <a href="https://pulp-platform.org/">PULP-Platform</a> “RI5CY” project (developed in collaboration between ETH-Zurich and University of Bologna), the CV32E40P represents the first open-source developed industrial-grade core.</li><li>This core was developed by the <a href="https://www.openhwgroup.org/membership/members/">OpenHW Group</a> which included significant contributions from the silicon industry. What makes this RISC-V implementation special is that it developed completely in the open-source, and second, it has been fully <strong>verified to modern industrial-standards</strong> (see <a href="https://eclipsefdn-openhwgroup.netlify.app/news/2020/12/10/core-v-cve4-rtl-freeze-milestone-achieved/">here</a>, and <a href="https://riscv.org/blog/2020/08/openhw-open-source-core-v-processor-ip-a-risc-v-story-that-leads-with-verification/">here</a>) where <strong>all verification collateral</strong> is included (e.g., detailed verification plans and functional coverage).</li><li>The OpenHW Group is also developing other cores including the PULP-Platform “Ariane”- derived CVA6 which is a 6-stage 64-bit machine capable of running Linux.</li><li>All OpenHW Group projects can be found in this <a href="https://github.com/openhwgroup">GitHub project</a>.</li></ul><p><strong>lowRISC Ibex : </strong><em>2-stage embedded RISC-V CPU core</em></p><ul><li>Originally based on the <a href="https://pulp-platform.org/">PULP-Platform</a> “Zero-riscy” project the Ibex also represents a fully open-source developed processor core</li><li>This core is being developed by <a href="https://www.lowrisc.org/">lowRISC</a> which is also a not-for-profit organization comprised of academic and industry members</li><li>Of note, the Ibex core formulates the main processing core within the Google-sponsored <a href="https://opentitan.org/">OpenTitan</a> project (more on this in a future post)</li></ul><p><strong>CHIPS Alliance SwerRV™</strong> : <em>A variety of 4- to 9-stage single or dual-issue CPU cores</em></p><ul><li>The SwerRV family of cores were developed internally at Western Digital and open-sourced in 2018 (following the completion of the development)</li><li>Unlike the OpenHW and LowRISC developments, the SweRV™ cores are more of an RTL and ISS release and full silicon deployment requires purchasing a support package from a commercial IP support provider.</li></ul><p>There are many other implementations out there, a full catalog can be found <a href="https://github.com/riscv/riscv-cores-list">here</a>.</p><p><em>If I have missed any permissively-licensed industrial-grade, silicon-RTL open-source RISC-V projects, please let me know!</em></p><h3>Summary</h3><p>An open, modular and common ISA, can create the conditions for more diversity, focused value creation and optimization of products. This is afforded by the property of de-coupling the ISA as an interface from the machine implementation allowing software tools and silicon to be independently optimized and segmented.</p><p>Much like general purpose open programming languages have liberated innovation in software development, an open and common computer language has the potential to bring similar energy and innovation not only to silicon developers, but to the electronics industry as a whole.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db70e7e7d79" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>