text:
# ⛓gzp

Multithreaded encoding.

## Why?

This crate provides a near drop in replacement for `Write` that has will compress chunks of data in parallel and write
to an underlying writer in the same order that the bytes were handed to the writer. This allows for much faster
compression of data.

### Supported Encodings:

- Gzip via [flate2](https://docs.rs/flate2/)
- Snappy via [rust-snappy](https://docs.rs/snap)

## Usage / Features

There are no features enabled by default. `pargz_default` enables `pargz` and `flate2_default`. `flate2_default` in turn
uses the default backed for `flate2`, which, as of this writing is the pure rust backend. `parsnap_default` is just a
wrapper over `parsnap`, which pulls in the `snap` dependency.

The following demonstrate common ways to override the features:

Simple way to enable both `pargz` and `parsnap`:

```toml
[dependencies]
gzp = { version = "*", features = ["pargz_default", "parsnap_default"] }
```

Use `pargz` to pull in `flate2` and `zlib-ng-compat` to use the `zlib-ng-compat` backend for `flate2` (most performant).

```toml
[dependencies]
gzp = { version = "*", features = ["pargz", "zlib-ng-compat"] }
```

To use Snap (could also use `parsnap_default`):

```toml
[dependencies]
gzp = { version = "*", no_default_features = true, features = ["parsnap"] }
```

To use both Snap and Gzip with specific backend:

```toml
[dependencies]
gzp = { version = "*", no_default_features = true, features = ["parsnap_default", "pargz", "zlib-ng-compat"] }
```

## Examples

Simple example

```rust
use std::{env, fs::File, io::Write};

use gzp::pargz::ParGz;

fn main() {
    let file = env::args().skip(1).next().unwrap();
    let writer = File::create(file).unwrap();
    let mut par_gz = ParGz::builder(writer).build();
    par_gz.write_all(b"This is a first test line\n").unwrap();
    par_gz.write_all(b"This is a second test line\n").unwrap();
    par_gz.finish().unwrap();
}
```

An updated version of [pgz](https://github.com/vorner/pgz).

```rust
use gzp::pargz::ParGz;
use std::io::{Read, Write};

fn main() {
    let chunksize = 64 * (1 << 10) * 2;

    let stdout = std::io::stdout();
    let mut writer = ParGz::builder(stdout).build();

    let stdin = std::io::stdin();
    let mut stdin = stdin.lock();

    let mut buffer = Vec::with_capacity(chunksize);
    loop {
        let mut limit = (&mut stdin).take(chunksize as u64);
        limit.read_to_end(&mut buffer).unwrap();
        if buffer.is_empty() {
            break;
        }
        writer.write_all(&buffer).unwrap();
        buffer.clear();
    }
    writer.finish().unwrap();
}
```

Same thing but using Snappy instead.

```rust
use gzp::parsnap::ParSnap;
use std::io::{Read, Write};

fn main() {
    let chunksize = 64 * (1 << 10) * 2;

    let stdout = std::io::stdout();
    let mut writer = ParSnap::builder(stdout).build();

    let stdin = std::io::stdin();
    let mut stdin = stdin.lock();

    let mut buffer = Vec::with_capacity(chunksize);
    loop {
        let mut limit = (&mut stdin).take(chunksize as u64);
        limit.read_to_end(&mut buffer).unwrap();
        if buffer.is_empty() {
            break;
        }
        writer.write_all(&buffer).unwrap();
        buffer.clear();
    }
    writer.finish().unwrap();
}
```

## Notes

- Files written with this are just Gzipped blocks catted together and must be read
  with `flate2::bufread::MultiGzDecoder`.

## Future todos

- Explore removing `Bytes` in favor of raw vec
- Check that block is actually smaller than when it started
- Update the CRC value with each block written
- Add a BGZF mode + tabix index generation (or create that as its own crate)
- Try with https://docs.rs/lzzzz/0.8.0/lzzzz/lz4_hc/fn.compress.html

## Benchmarks

All benchmarks were run on the file in `./bench-data/shakespeare.txt` catted together 100 times which creats a rough
550Mb file.

Note that there are far more comprehensive comparisons of the tradeoffs in differet compression algorithms / compression
levels elsewhere on the interent. This is meant to give rough understanding of the tradoffs involved.

| Name | Num Threads | Compression Level | Buffer Size | Time | File Size |
| --- | - | ----------------- | -----------| ---- | --------- |
| Gzip Only | NA | 3 | 128 Kb | 6.6s | 218 Mb |
| Gzip | 1 | 3 | 128 Kb | 2.4s | 223 Mb |
| Gzip | 4 | 3 | 128 Kb | 1.2s | 223 Mb |
| Gzip | 8 | 3 | 128 Kb | 0.8s | 223 Mb |
| Gzip | 16 | 3 | 128 Kb | 0.6s | 223 Mb |
| Gzip | 30 | 3 | 128 Kb | 0.6s | 223 Mb |
| Snap Only | NA | NA | 128 Kb | 1.6s | 333 Mb |
| Snap | 1 | NA | 128 Kb | 0.7s | 333 Mb |
| Snap | 4 | NA | 128 Kb | 0.5s | 333 Mb |
| Snap | 8 | NA | 128 Kb | 0.4s | 333 Mb |
| Snap | 16 | NA | 128 Kb | 0.4s | 333 Mb |
| Snap | 30 | NA | 128 Kb | 0.4s | 333 Mb |

![benchmarks](./violin.svg)

license: Unlicense,MIT

repository: isgasho/gzp

detected_licenses: Unlicense MIT

repo_name: isgasho/gzp


text:
---
title: Advent of Code. Year 2015. Day 12
date: 2019-07-08T04:00:14.179Z
description: Solution to Advent of Code Year 2015 - Day 12
tags:
  - aoc-2015
---
## --- Day 12: JSAbacusFramework.io ---

In today's challenge we have to help Santa's Accounting-Elves. They have a `JSON` document which contains a variety of things: arrays (`[1,2,3]`), objects (`{"a":1, "b":2}`), numbers, and strings.

### Part 1

In the first part, we need to find the sum of all numbers in `JSON`. To solve this part, I used `Regex.Matches` to get all numbers from `JSON` string. Then I just iterated through all of them to get the resulting sum.

```csharp
public string Part1(IEnumerable<string> lines)
{
  var input = GetInput(lines);
  var matches = Regex.Matches(input, @"-?\d+");
  var sum = 0;
  foreach (Match match in matches)
  {
    if (int.TryParse(match.Value, out var result))
      sum += result;
    else
      throw new Exception("Bad string");
  }
  return sum.ToString();
}
```

### Part 2

In the second part, we also need to find the sum of all numbers in `JSON` but this time we need to ignore any object and all of its children which has any value `"red"`.

This time we can't just parse all numbers, so we have to parse `JSON` itself. To do that, I used a library called `Json.NET`. I created a method that can figure out which method should be called with a given token. For example, if the token is `object`, then `ProcessObject` method will be called.

```csharp
private static int ProcessToken(JToken token)
{
  switch (token)
  {
    case JArray array:
      return ProcessArray(array);
    case JObject jObject:
      return ProcessObject(jObject);
    case JValue value:
      return ProcessValue(value);
  }

  return 0;
}
```

* To process array, I need to call `ProcessToken` on all elements of that array.

```csharp
private static int ProcessArray(JArray array)
{
  return array.Children().Sum(ProcessToken);
}
```

* To process value I need to try parse value to an integer and if that parse succeeds then I am returning it otherwise I am returning `0`.

```csharp
private static int ProcessValue(JValue value)
{
  return int.TryParse(value.Value.ToString(), out var elem) ? elem : 0;
}
```

* Parsing object a little bit more difficult. First, I need to iterate through all of the properties to check if that property contains the value `"red"`. If `"red"` is found I am returning return value `0`. Otherwise, I call `ProcessToken` on all properties and get the sum.

```csharp
private static int ProcessObject(JObject jObject)
{
  foreach (var jProperty in jObject.Properties())
  {
    if (!(jProperty.Value is JValue jValue))
      continue;

    if (jValue.Value.ToString() == "red")
      return 0;
  }

  return jObject.Properties().Sum(jProperty => ProcessToken(jProperty.Value));
}
```

The final piece is to parse the input and call `ProcessArray` on it.

```csharp
public string Part2(IEnumerable<string> lines)
{
  var input = GetInput(lines);
  return ProcessArray(JArray.Parse(input)).ToString();
}
```

- - -

Links:

* [Puzzle](https://adventofcode.com/2015/day/12)
* [Solution](https://github.com/PDmatrix/advent-of-code/tree/master/CSharp/Solutions/2015/12)

license: MIT

branch_name: refs/heads/master

extension: md

gha_language: JavaScript

gha_license_id: MIT

license_type: permissive


text:
---
layout: default
---

# 1993-09-04 - net.history (flashback)

## Header Data

From: Anonymous<EMAIL_ADDRESS>To<EMAIL_ADDRESS>Message Hash: cfb19be63cdfc4551f3828147d45c38167e5a8947169d750d25e493c8a71fd36

Message ID<EMAIL_ADDRESS>Reply To: _N/A_

UTC Datetime: 1993-09-04 01:45:32 UTC

Raw Date: Fri, 3 Sep 93 18:45:32 PDT

## Raw message

```
{% raw  %}From: Anonymous<EMAIL_ADDRESS>Date: Fri, 3 Sep 93 18:45:32 PDT
To<EMAIL_ADDRESS>Subject: net.history (flashback)
Message-ID<EMAIL_ADDRESS>MIME-Version: 1.0
Content-Type: text/plain

On Fri, 3 Sep 1993 02:20:00 GMT,
 Bill Murray<EMAIL_ADDRESS>writes -

> I am reminded of a story, perhaps apocryphal.  In the middle
> seventies Fortune magazine was working a feature on computer
> crime.  Most of the experts that they interviewed told them
> that the security on most of the nation's commercial time
> sharing systems was pretty good.  However, they admitted that
> one convicted felon and hacker, Jerry Schnieder, would tell
> them otherwise.  Of course Fortune had to interview him.

 I remember this story, Bill, and I find this correlation
 interesting. It's funny how Schneider's name hasn't really
 surfaced in such a long time. In fact, once I think about the
 real parallels to Herren Doktor's lip service, I find it even
 frightening, given the anticipated impact with which her opinions
 seem to affect governmentalism.

 For what its worth, there was another interesting item concerning
 Schneider which appeared in Info Security News this issue, in their
 "Top Ten Events" article of the top ten info-security events since
 the inception of computers.

 I relay the pertinent portion of this article below:

 "Jerry Schneider was not the first computer crook, which he
 became at 18; nor was he the first computer security consultant,
 which he became at age 21. Still, his antics on both sides of
 the law helped bring computer crime to the awareness of the
 public in general and business managers in particular.

 Although still in high school in 1968, Schneider started a
 company called Creative Systems Enterprises and began selling
 electronic telecommunications gadgets he invented. Each day as
 he passed the Pacific Telephone and Telegraph Company office, he
 scavenged the firm's dumpster for discarded equipment that could
 be used to build his gadgets. He also collected a wide variety
 of documents, ranging from invoices to training manuals. Within
 just a few years, he became an expert on telephone company
 technology and business, and reportedly knew more about Pacific
 Telephone's telephone equipment supply procedures than any of
 its employees.

 In June, 1971, Schneider set into motion an elaborate plan to
 steal new telephone equipment from Pacific Telephone and resell
 it as refurbished equipment through Creative Systems. Eventually
 the scam would net him hundred of thousands of dollars worth of
 Pacific Telephone equipment. Scneider accessed Pacific
 Telephone's computerized ordering system and by using a telephone
 card dialer succeeded in placing orders for equipment. To
 complete the scam, he needed to learn the telephone equipment
 budgets for individual telephone company's sites, equipment
 inventory levels and other key pieces of information. He
 gathered  the required information by getting access codes to a
 commercial time-sharing service used by the telephone company
 for inventory control and parts distribution.

 In January 1972, acting on information provided to them by one
 of Schneider's former employees, law enforcers raided
 Schneider's offices and a warehouse where they found equipment
 the district attorney said was worth $8,000. They also learned
 at that time that Schneider had stolen a total of $125,000 worth
 of equipment. Later, Schneider would admit that he had taken
 close to $900,000  worth of goods.

 The day after his arrest on February 8, 1972, newspapers across
 the country called it one of the most famous computer crimes
 ever. "How he Folded, Spindled, and Mutilated," one headline
 said.

 In a plea bargain, Schneider agreed to plead guilty to one
 count of grand theft of $5,000 worth of equipment. In July, he
 was sentenced to two monyhs in a minimum security corrections
 institution. In all, however, served 40 days and paid a $500
 fine.

 Later that year, Schneider, then only 21 years old, formed a
 computer consulting firm catering to companies that did not want
 to get ripped off by cyber-crooks. He stayed in the business
 until 1977. Today, he owns a firm that sells off-shore banking
 services.

8<------ Gut Here ---------------

Gee, imagine that.

Ye olde Spooge Meister    spooge /spooj/ 1. Inexplicable or arcane code
<EMAIL_ADDRESS>          or random and probably incorrect output
                                 from a computer program.

{% endraw %}
```

## Thread

+ Return to [September 1993](/archive/1993/09)

+ Return to "[Anonymous <nowhere@bsu-cs.bsu.edu>](/authors/anonymous_nowhere_at_bsucs_bsu_edu_)"

+ 1993-09-04 (Fri, 3 Sep 93 18:45:32 PDT) - net.history (flashback) - _Anonymous<EMAIL_ADDRESS>


text:
### tuktu.processors.EOFBufferProcessor
Buffers until EOF (end of data stream) is found.

  * **id** *(type: string)* `[Required]`

  * **result** *(type: string)* `[Required]`

  * **config** *(type: object)* `[Required]`

repository: dmassart/Tuktu

repo_name: dmassart/Tuktu


text:
 Chrome-Extension-Meta-Refresh-Killer

Kills ☠ meta http-equiv="refresh" Tags 𝗕𝗘𝗙𝗢𝗥𝗘 They Refresh/Redirect You! ★★★★★

Save memory: Only enable this extension when needed

For example to stop one website from refreshing over-and over again...

Set to Disabled: chrome://flags/#disallow-doc-written-script-loads

𝙈𝙚𝙩𝙖-𝙍𝙚𝙛𝙧𝙚𝙨𝙝-𝙆𝙞𝙡𝙡𝙚𝙧 helps you by:

⏰ Preventing the page from self-refresh.

↬ Preventing the page from being redirected.

🙆 Keeping 𝙮𝙤𝙪 in control.

✿ ❀ ❁ ✿ ❀ ❁ ✿ ❀ ❁

👔 Pro Tip ⧣𝟭:

Have JavaScript disabled globally?
Good! it will keep you safe!

This is how some web-developers will try to force you to enable it again for their websites:

<noscript>
  <meta http-equiv='REFRESH' content='0;URL=...'
</noscript>

But now you don't have to!
𝙈𝙚𝙩𝙖-𝙍𝙚𝙛𝙧𝙚𝙨𝙝-𝙆𝙞𝙡𝙡𝙚𝙧 will allow you to view any page without getting redirected.

✿ ❀ ❁ ✿ ❀ ❁ ✿ ❀ ❁

⧣𝟮 uninstall AdBlock/AdBlock Plus
install 𝙪𝘽𝙡𝙤𝙘𝙠 𝙊𝙧𝙞𝙜𝙞𝙣. AdBlock had sold-out.

✿ ❀ ❁ ✿ ❀ ❁ ✿ ❀ ❁

⧣𝟯 install 𝙍𝙚𝙢𝙤𝙫𝙚-𝙍𝙚𝙙𝙞𝙧𝙚𝙘𝙩𝙨
it keeps you from clicking on redirect-links.

chrome.google.com/webstore/detail/bckcmceomgfhebkfbogignipjenidnmp

✿ ❀ ❁ ✿ ❀ ❁ ✿ ❀ ❁

⧣𝟰 Disable JavaScript and cookies globally
(chrome://settings/content)

You can later enable them just for few safe websites.

You can safely enable JS&cookies for Google, YouTube and Facebook, by adding those entries:
[*.]google.com
[*.]youtube.com
[*.]facebook.com
to:
(chrome://settings/contentExceptions#cookies)
(chrome://settings/contentExceptions#javascript)

You easily enable new websites in-case needed using the new icons for disabled JS/cookies on the your address-bar.

✿ ❀ ❁ ✿ ❀ ❁ ✿ ❀ ❁

𝙈𝙚𝙩𝙖-𝙍𝙚𝙛𝙧𝙚𝙨𝙝-𝙆𝙞𝙡𝙡𝙚𝙧 runs 100% offline, does not uses online-services, include no ads, no tracking, completely free and open-source:
github.com/eladkarako/Chrome-Extension-Meta-Refresh-Killer

Developer's HUB / Changelog

<IP_ADDRESS>
* improving clean-up of the current DOM, unloading as much objects from the global-scope as possible, before loading the "no-redirects" modified HTML, this helps to prevent double objects, when loading SCRIPT elements again... :]

<IP_ADDRESS>
+ added support for Chrome's idle state.
- reduce package size.
- limit re-discovery to once per-page life-cycle state-change (load/ready).

<IP_ADDRESS>
* meta data update.

<IP_ADDRESS>
* code-refactor to use DOM-structure (OO) instead of text-based modifications.
+ fix badly written web-pages that loads http: resources into https: pages (mix-content fix) to avoid warnings.
* optimized engine's performances.

<IP_ADDRESS>
* apply action to main and all of the sub-frames (if any).

<IP_ADDRESS>
+ adding some more break-point for invalid frames.

<IP_ADDRESS>
* engine update.

<IP_ADDRESS>
+ badge info total of meta-refresh tags removed (usually just one..)
* engine update: were no meta refresh tags? do nothing.

<IP_ADDRESS>
* engine update: minimize stream write usage.

<IP_ADDRESS>
+ initial.

license: Unlicense


text:
# narrative-reputation deployment for production

Requirements:
- Requires the rep-application-production-yaml configmap
- Requires the rep-application-secret-yaml secret
- Requires the cloud-sql-proxy secret

# Create the application properties and secrets

Create the production configmap:
```
kubectl config use-context gke_production-narrative_us-central1_production-cluster
kubectl -n production create configmap rep-application-production-yaml --from-file=./application-production.yaml
```

Get the `production - rep-application-secret.yaml` file from 1Password. Create the secret:

```
kubectl -n production create secret generic rep-application-secret-yaml --from-file=./application-secret.yaml
```
Remove `application-secret.yaml`.

# Creating the cloud-sql-proxy IAM user and secret

See narrative-core for configuring these credentials. They should already exist.

# Deploy

Set context:

```
kubectl config use-context gke_production-narrative_us-central1_production-cluster
```

Create the production configmap (see above).

Create the production secret (see above).

Deploy narrative-reputation:

```
kubectl apply -f narrative-reputation-deployment.yml
```

repository: jimador/narrative

repo_name: jimador/narrative


text:
# d3-word-wrap

Wrap text within a bounding box.

## Installing

If you use NPM, `npm install d3-word-wrap`. Otherwise, download the
[latest release](https://github.com/MikeWinter/d3-word-wrap/releases/latest).

## API Reference

# **wordWrap**([*width*], [*height*])

Returns a word wrapper, optionally configured with the given `width` and `height` bounds.

# *wrap*(*selection*)

Applies the word wrapper to the given `selection`.

# *wrap*.**width**([*width*])

If this method is called with an argument, the width bound is set to the value `width` and this
word wrapper (`wrap`) is returned. Otherwise, this method returns the current width bound.

# *wrap*.**height**([*height*])

If this method is called with an argument, the height bound is set to the value `height` and this
word wrapper (`wrap`) is returned. Otherwise, this method returns the current height bound.


text:
# Hangman
Simple Hangman game in the terminal, written in Python.

![Hangman Image](https://miro.medium.com/max/636/1*TzbmJ5RWXeyjnT1ZuG664A.png)

## Installation

This project uses pure Python. You can download Python [here](https://www.python.org/downloads/) for your specific platform.

Then, just clone the project using
```bash
git clone https://github.com/tcrasset/hangman.git
```

## Usage

Navigate inside your recently cloned directory and simply run
```
python main.py
```

## Interface

![Terminal game (Image)](assets/hangman.png)

*Tom Crasset, 7/01/2021, MIT License*

repository: tcrasset/hangman

branch_name: refs/heads/main

repo_name: tcrasset/hangman


text:
## Introduction
This small project may be used as a internal classified hosted in intranet. Still WIP

## Install Software
1. Install GIT http://git-scm.com/
2. Install tortoiseGIT https://code.google.com/p/tortoisegit/
3. Install Node http://nodejs.org/
4. Install grunt http://gruntjs.com/
5. Install Mongoose server http://cesanta.com/mongoose.shtml or
server of your choice

## Clone Repo
Clone GIT repository
```
git clone https://github.com/rajakvk/classified.git
```

## Initial commands
1. On command prompt, go to taClassified tolder and run
```
npm install
grunt
grunt watch
```
Point mongoose server to the cloned folder (build directory)

## Business problem
This mock project trying to solve the business problem mentioned as under
* Internal classified
* Post advertisement
* Expire in after n days
* List chronologically
* Search feature
* Sort feature

repository: rajakvk/classified

repo_name: rajakvk/classified


text:
# BERT Inference Using TensorRT

This subfolder of the BERT TensorFlow repository, tested and maintained by NVIDIA, provides scripts to perform high-performance inference using NVIDIA TensorRT.

## Table Of Contents

- [Model Overview](#model-overview)
   * [Model Architecture](#model-architecture)
   * [TensorRT Inference Pipeline](#tensorrt-inference-pipeline)
   * [Version Info](#version-info)
- [Setup](#setup)
   * [Requirements](#requirements)
- [Quick Start Guide](#quick-start-guide)
  * [(Optional) Trying a different configuration](#optional-trying-a-different-configuration)
- [Advanced](#advanced)
  * [Scripts and sample code](#scripts-and-sample-code)
  * [Command-line options](#command-line-options)
  * [TensorRT inference process](#tensorrt-inference-process)
- [Accuracy](#accuracy)
  * [Evaluating Post-Training-Quantization INT8 accuracy](#evaluating-ptq-post-training-quantization-int8-accuracy-using-the-squad-dataset)
  * [Evaluating Quantization-Aware-Training INT8 accuracy](#evaluating-qat-quantization-aware-training-int8-accuracy-using-the-squad-dataset)
- [Experimental](#experimental)
  * [Variable sequence length](#variable-sequence-length)
      * [Run command lines](#run-command-lines)
  * [Sparsity with Quantization Aware Training](#sparsity-with-quantization-aware-training)
      * [Megatron-LM for Question Answering](#megatron-lm-for-question-answering)
- [Performance](#performance)
  * [Benchmarking](#benchmarking)
       * [TensorRT inference benchmark](#tensorrt-inference-benchmark)
  * [Results](#results)
    * [Inference performance: NVIDIA A100](#inference-performance-nvidia-a100-40gb)
      * [BERT Base](#bert-base)
      * [BERT Large](#bert-large)
      * [Megatron Large Sparse](#megatron-large-with-sparsity)
    * [Inference performance: NVIDIA T4](#inference-performance-nvidia-t4-16gb)
      * [BERT Base](#bert-base-1)
      * [BERT Large](#bert-large-1)

## Model overview

BERT, or Bidirectional Encoder Representations from Transformers, is a new method of pre-training language representations which obtains state-of-the-art results on a wide array of Natural Language Processing (NLP) tasks. This model is based on the [BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding](https://arxiv.org/abs/1810.04805) paper. NVIDIA's BERT is an optimized version of [Google's official implementation](https://github.com/google-research/bert), leveraging mixed precision arithmetic and Tensor Cores for faster inference times while maintaining target accuracy.

Other publicly available implementations of BERT include:
1. [NVIDIA PyTorch](https://github.com/NVIDIA/DeepLearningExamples/tree/master/PyTorch/LanguageModeling/BERT)
2. [Hugging Face](https://github.com/huggingface/pytorch-pretrained-BERT)
3. [codertimo](https://github.com/codertimo/BERT-pytorch)
4. [gluon-nlp](https://github.com/dmlc/gluon-nlp/tree/master/scripts/bert)
5. [Google's official implementation](https://github.com/google-research/bert)

### Model architecture

BERT's model architecture is a multi-layer bidirectional Transformer encoder. Based on the model size, we have the following two default configurations of BERT:

| **Model** | **Hidden layers** | **Hidden unit size** | **Attention heads** | **Feed-forward filter size** | **Max sequence length** | **Parameters** |
|:---------:|:----------:|:----:|:---:|:--------:|:---:|:----:|
|BERT-Base |12 encoder| 768| 12|4 x  768|512|110M|
|BERT-Large|24 encoder|1024| 16|4 x 1024|512|330M|

Typically, the language model is followed by a few task-specific layers. The model used here includes layers for question answering.

### TensorRT Inference Pipeline

BERT inference consists of three main stages: tokenization, the BERT model, and finally a projection of the tokenized prediction onto the original text.
Since the tokenizer and projection of the final predictions are not nearly as compute-heavy as the model itself, we run them on the host. The BERT model is GPU-accelerated via TensorRT.

The tokenizer splits the input text into tokens that can be consumed by the model. For details on this process, see [this tutorial](https://mccormickml.com/2019/05/14/BERT-word-embeddings-tutorial/).

To run the BERT model in TensorRT, we construct the model using TensorRT APIs and import the weights from a pre-trained TensorFlow checkpoint from [NGC](https://ngc.nvidia.com/models/nvidian:bert_tf_v2_large_fp16_128). Finally, a TensorRT engine is generated and serialized to the disk. The various inference scripts then load this engine for inference.

Lastly, the tokens predicted by the model are projected back to the original text to get a final result.

### Version Info

The following software version configuration has been tested:

|Software|Version|
|--------|-------|
|Python|>=3.6.x|
|TensorRT|<IP_ADDRESS>|
|CUDA|11.3.1|

## Setup

The following section lists the requirements that you need to meet in order to run the BERT model.

### Requirements

This demo BERT application can be run within the TensorRT OSS build container. If running in a different environment, following packages are required.

* [NGC CLI](https://ngc.nvidia.com/setup/installers/cli) - for downloading BERT checkpoints from NGC.
* PyPI Packages:
  * [pycuda](https://pypi.org/project/pycuda/) (tested v2019.1.2)
  * [onnx](https://pypi.org/project/onnx) (tested v1.8.1)
  * [tensorflow](https://pypi.org/project/tensorflow/) (tested v2.4.1)
  * [torch](https://pypi.org/project/torch/1.6.0/) (tested v1.8.1)
* NVIDIA [Volta](https://www.nvidia.com/en-us/data-center/volta-gpu-architecture/), [Turing](https://www.nvidia.com/en-us/geforce/turing/) or [Ampere](https://www.nvidia.com/en-us/data-center/nvidia-ampere-gpu-architecture/) based GPU.

## Quick Start Guide

1. Build and launch the container as described in [TensorRT OSS README](https://github.com/NVIDIA/TensorRT/blob/master/README.md).

    **Note:** After this point, all commands should be run from within the container.

2. Verify TensorRT installation by printing the version:
   For example:
    ```bash
    python3 -c "import tensorrt as trt; print(trt.__version__)"
    ```

3. Download the SQuAD dataset and BERT checkpoints:
    ```bash
    cd $TRT_OSSPATH/demo/BERT
    ```

    Download SQuAD v1.1 training and dev dataset.
    ```bash
    bash ./scripts/download_squad.sh
    ```

    Download Tensorflow checkpoints for BERT large model with sequence length 128, fine-tuned for SQuAD v2.0.
    ```bash
    bash scripts/download_model.sh
    ```

**Note:** Since the datasets and checkpoints are stored in the directory mounted from the host, they do *not* need to be downloaded each time the container is launched.

4. Build a TensorRT engine. To build an engine, run the `builder.py` script. For example:
    ```bash
    mkdir -p engines && python3 builder.py -m models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_128_v19.03.1/model.ckpt -o engines/bert_large_128.engine -b 1 -s 128 --fp16 -c models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_128_v19.03.1
    ```

    This will build an engine with a maximum batch size of 1 (`-b 1`), and sequence length of 128 (`-s 128`) using mixed precision (`--fp16`) using the BERT Large SQuAD v2 FP16 Sequence Length 128 checkpoint (`-c models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_128_v19.03.1`).

5. Run inference. Two options are provided for running the model.

    a. `inference.py` script
    This script accepts a passage and question and then runs the engine to generate an answer.
    For example:
    ```bash
    python3 inference.py -e engines/bert_large_128.engine -p "TensorRT is a high performance deep learning inference platform that delivers low latency and high throughput for apps such as recommenders, speech and image/video on NVIDIA GPUs. It includes parsers to import models, and plugins to support novel ops and layers before applying optimizations for inference. Today NVIDIA is open-sourcing parsers and plugins in TensorRT so that the deep learning community can customize and extend these components to take advantage of powerful TensorRT optimizations for your apps." -q "What is TensorRT?" -v models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_128_v19.03.1/vocab.txt
    ```

    b. `inference.ipynb` Jupyter Notebook
    The Jupyter Notebook includes a passage and various example questions and allows you to interactively make modifications and see the outcome.
    To launch the Jupyter Notebook from inside the container, run:
    ```bash
    jupyter notebook --ip <IP_ADDRESS> inference.ipynb
    ```
    Then, use your browser to open the link displayed. The link should look similar to: `http://<IP_ADDRESS>:8888/?token=<TOKEN>`

6. Run inference with CUDA Graph support.

    A separate python `inference_c.py` script is provided to run inference with CUDA Graph support. This is necessary since CUDA Graph is only supported through CUDA C/C++ APIs, not pyCUDA. The `inference_c.py` script uses pybind11 to interface with C/C++ for CUDA graph capturing and launching. The cmdline interface is the same as `inference.py` except for an extra `--enable-graph` option.

    ```bash
    mkdir -p build; pushd build
    cmake .. -DPYTHON_EXECUTABLE=$(which python)
    make -j
    popd
    python3 inference_c.py -e engines/bert_large_128.engine --enable-graph -p "TensorRT is a high performance deep learning inference platform that delivers low latency and high throughput for apps such as recommenders, speech and image/video on NVIDIA GPUs. It includes parsers to import models, and plugins to support novel ops and layers before applying optimizations for inference. Today NVIDIA is open-sourcing parsers and plugins in TensorRT so that the deep learning community can customize and extend these components to take advantage of powerful TensorRT optimizations for your apps." -q "What is TensorRT?" -v models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_128_v19.03.1/vocab.txt
    ```

    A separate C/C++ inference benchmark executable `perf` (compiled from `perf.cpp`) is provided to run inference benchmarks with CUDA Graph. The cmdline interface is the same as `perf.py` except for an extra `--enable_graph` option.

    ```bash
    build/perf -e engines/bert_large_128.engine -b 1 -s 128 -w 100 -i 1000 --enable_graph
    ```

### (Optional) Trying a different configuration

If you would like to run another configuration, you can manually download checkpoints using the included script. For example, run:
```bash
bash scripts/download_model.sh base
```
to download a BERT Base model instead of the default BERT Large model.

To view all available model options, run:
```bash
bash scripts/download_model.sh -h
```

## Advanced

The following sections provide greater details on inference with TensorRT.

### Scripts and sample code

In the `root` directory, the most important files are:

- `builder.py` - Builds an engine for the specified BERT model
- `Dockerfile` - Container which includes dependencies and model checkpoints to run BERT
- `inference.ipynb` - Runs inference interactively
- `inference.py` - Runs inference with a given passage and question
- `perf.py` - Runs inference benchmarks

The `scripts/` folder encapsulates all the one-click scripts required for running various supported functionalities, such as:

- `build.sh` - Builds a Docker container that is ready to run BERT
- `launch.sh` - Launches the container created by the `build.sh` script.
- `download_model.sh` - Downloads pre-trained model checkpoints from NGC
- `inference_benchmark.sh` - Runs an inference benchmark and prints results

Other folders included in the `root` directory are:

- `helpers` - Contains helpers for tokenization of inputs

The `infer_c/` folder contains all the necessary C/C++ files required for CUDA Graph support.
- `bert_infer.h` - Defines necessary data structures for running BERT inference
- `infer_c.cpp` - Defines C/C++ interface using pybind11 that can be plugged into `inference_c.py`
- `perf.cpp` - Runs inference benchmarks. It is equivalent to `perf.py`, with an extra option `--enable_graph` to enable CUDA Graph support.

### Command-line options

To view the available parameters for each script, you can use the help flag (`-h`).

### TensorRT inference process

As mentioned in the [Quick Start Guide](#quick-start-guide), two options are provided for running inference:
1. The `inference.py` script which accepts a passage and a question and then runs the engine to generate an answer. Alternatively, this script can be used to run inference on the Squad dataset.
2. The `inference.ipynb` Jupyter Notebook which includes a passage and various example questions and allows you to interactively make modifications and see the outcome.

## Accuracy

### Evaluating PTQ (post-training quantization) Int8 Accuracy Using The SQuAD Dataset
1.  Download Tensorflow checkpoints for a BERT Large FP16 SQuAD v2 model with a sequence length of 384:
    ```bash
    bash scripts/download_model.sh large 384 v2
    ```

2. Build an engine:

    **Turing and Ampere GPUs**
    ```bash
    # QKVToContextPlugin and SkipLayerNormPlugin supported with INT8 I/O. To enable, use -imh and -iln builder flags respectively.
    mkdir -p engines && python3 builder.py -m models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/model.ckpt -o engines/bert_large_384_int8mix.engine -b 1 -s 384 --int8 --fp16 --strict -c models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1 --squad-json ./squad/train-v1.1.json -v models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/vocab.txt --calib-num 100 -iln -imh
    ```

    **Xavier GPU**
    ```bash
    # Only supports SkipLayerNormPlugin running with INT8 I/O. Use -iln builder flag to enable.
    mkdir -p engines && python3 builder.py -m models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/model.ckpt -o engines/bert_large_384_int8mix.engine -b 1 -s 384 --int8 --fp16 --strict -c models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1 --squad-json ./squad/train-v1.1.json -v models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/vocab.txt --calib-num 100 -iln
    ```

    **Volta GPU**
    ```bash
    # No support for QKVToContextPlugin or SkipLayerNormPlugin running with INT8 I/O. Don't specify -imh or -iln in builder flags.
    mkdir -p engines && python3 builder.py -m models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/model.ckpt -o engines/bert_large_384_int8mix.engine -b 1 -s 384 --int8 --fp16 --strict -c models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1 --squad-json ./squad/train-v1.1.json -v models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/vocab.txt --calib-num 100
    ```

    This will build an engine with a maximum batch size of 1 (`-b 1`), calibration dataset squad (`--squad-json ./squad/train-v1.1.json`), calibration sentences number 100 (`--calib-num 100`), and sequence length of 384 (`-s 384`) using INT8 mixed precision computation where possible (`--int8 --fp16 --strict`).

3. Run inference using the squad dataset, and evaluate the F1 score and exact match score:
    ```bash
    python3 inference.py -e engines/bert_large_384_int8mix.engine -s 384 -sq ./squad/dev-v1.1.json -v models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/vocab.txt -o ./predictions.json
    python3 squad/evaluate-v1.1.py  squad/dev-v1.1.json  ./predictions.json 90
    ```
### Evaluating QAT (quantization aware training) Int8 Accuracy Using The SQuAD Dataset
1.  Download checkpoint for BERT Large FP16 SQuAD v1.1 model with sequence length of 384:
    ```bash
    bash scripts/download_model.sh pyt v1_1
    ```

2. Build an engine:

    **Turing and Ampere GPUs**
    ```bash
    # QKVToContextPlugin and SkipLayerNormPlugin supported with INT8 I/O. To enable, use -imh and -iln builder flags respectively.
    mkdir -p engines && python3 builder.py -o engines/bert_large_384_int8mix.engine -b 1 -s 384 --int8 --fp16 --strict -c models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1 -v models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/vocab.txt -x models/fine-tuned/bert_pyt_onnx_large_qa_squad11_amp_fake_quant_v1/bert_large_v1_1_fake_quant.onnx -iln -imh
    ```

    **Xavier GPU**
    ```bash
    # Only supports SkipLayerNormPlugin running with INT8 I/O. Use -iln builder flag to enable.
    mkdir -p engines && python3 builder.py -o engines/bert_large_384_int8mix.engine -b 1 -s 384 --int8 --fp16 --strict -c models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1 -v models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/vocab.txt -x models/fine-tuned/bert_pyt_onnx_large_qa_squad11_amp_fake_quant_v1/bert_large_v1_1_fake_quant.onnx -iln
    ```

    **Volta GPU**
    ```bash
    # No support for QKVToContextPlugin or SkipLayerNormPlugin running with INT8 I/O. Don't specify -imh or -iln in builder flags.
    mkdir -p engines && python3 builder.py -o engines/bert_large_384_int8mix.engine -b 1 -s 384 --int8 --fp16 --strict -c models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1 -v models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/vocab.txt -x models/fine-tuned/bert_pyt_onnx_large_qa_squad11_amp_fake_quant_v1/bert_large_v1_1_fake_quant.onnx
    ```

    This will build and engine with a maximum batch size of 1 (`-b 1`) and sequence length of 384 (`-s 384`) using INT8 mixed precision computation where possible (`--int8 --fp16 --strict`).

3. Run inference using the squad dataset, and evaluate the F1 score and exact match score:

    ```bash
    python3 inference.py -e engines/bert_large_384_int8mix.engine -s 384 -sq ./squad/dev-v1.1.json -v models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/vocab.txt -o ./predictions.json
    python3 squad/evaluate-v1.1.py  squad/dev-v1.1.json  ./predictions.json 90
    ```
## Experimental

### Variable sequence length
In our prior implementation, we used inputs padded to max length along with corresponding input masks to handle variable sequence length inputs in a batch. The padding results in some wasted computations which can be avoided by handling variable sequence length inputs natively. Now we have a new approach called the variable sequence length method. By concatenating each input id into a single long input id, and concatenating each input segment id into a single long segment id, TensorRT can know the exact starts and ends by providing an extra sequence length buffer that contains the start and end positions of each sequence. Now we can eliminate the wasted computation in the input paddings.

Note this is an experimental feature because we only support Xavier+ GPUs, also there is neither FP32 support nor INT8 PTQ calibration.

1.  Download checkpoint for BERT Large FP16 SQuAD v1.1 model with sequence length of 384:
    ```bash
    bash scripts/download_model.sh pyt v1_1
    ```

2. Build an engine:

    **FP16 engine**
    ```bash
    mkdir -p engines && python3 builder_varseqlen.py -x models/fine-tuned/bert_pyt_onnx_large_qa_squad11_amp_fake_quant_v1/bert_large_v1_1_fake_quant.onnx -o engines/bert_varseq_fp16.engine -b 1 -s 64 --fp16 -c models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1 -v models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/vocab.txt
    ```

    This will build and engine with a maximum batch size of 1 (`-b 1`) and sequence length of 64 (`-s 64`) using FP16 precision computation where possible (`--fp16`).

    **INT8 engine**
    ```bash
    mkdir -p engines && python3 builder_varseqlen.py -x models/fine-tuned/bert_pyt_onnx_large_qa_squad11_amp_fake_quant_v1/bert_large_v1_1_fake_quant.onnx -o engines/bert_varseq_int8.engine -b 1 -s 256 --int8 --fp16 -c models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1 -v models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/vocab.txt
    ```

    This will build and engine with a maximum batch size of 1 (`-b 1`) and sequence length of 256 (`-s 256`) using INT8 precision computation where possible (`--int8`).

3. Run inference

    Evaluate the F1 score and exact match score using the squad dataset:

    ```bash
    python3 inference_varseqlen.py -e engines/bert_varseq_int8.engine -s 256 -sq ./squad/dev-v1.1.json -v models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/vocab.txt -o ./predictions.json
    python3 squad/evaluate-v1.1.py  squad/dev-v1.1.json  ./predictions.json 90
    ```

    Run the quesion and answer mode:

    ```bash
    python3 inference_varseqlen.py -e engines/bert_varseq_int8.engine -p "TensorRT is a high performance deep learning inference platform that delivers low latency and high throughput for apps such as recommenders, speech and image/video on NVIDIA GPUs. It includes parsers to import models, and plugins to support novel ops and layers before applying optimizations for inference. Today NVIDIA is open-sourcing parsers and plugins in TensorRT so that the deep learning community can customize and extend these components to take advantage of powerful TensorRT optimizations for your apps." -q "What is TensorRT?" -v models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/vocab.txt -s 256
    ```

4. Collect performance data

    ```bash
    python3 perf_varseqlen.py -e engines/bert_varseq_int8.engine -b 1 -s 256
    ```

    This will collect performance data run use batch size 1 (`-b 1`) and sequence length of 256 (`-s 256`).

5. Collect performance data with CUDA graph enabled

    We can use the same `inference_c.py` and `build/perf` to collect performance data with cuda graph enabled. The command line is the same as run without variable sequence length.

### Sparsity with Quantization Aware Training

Fine-grained 2:4 structured sparsity support introduced in NVIDIA Ampere GPUs can produce significant performance gains in BERT inference. The network is first trained using dense weights, then fine-grained structured pruning is applied, and finally the remaining non-zero weights are fine-tuned with additional training steps. This method results in virtually no loss in inferencing accuracy.

Using INT8 precision with quantization scales obtained from Post-Training Quantization (PTQ) can produce additional performance gains, but may also result in accuracy loss. Alternatively, for PyTorch-trained models, NVIDIA [PyTorch-Quantization toolkit](https://github.com/NVIDIA/TensorRT/tree/master/tools/pytorch-quantization) can be leveraged to perform quantized fine tuning (a.k.a. Quantization Aware Training or QAT) and generate the INT8 quantization scales as part of training. This generally results in higher accuracy compared to PTQ.

To demonstrate the potential speedups from these optimizations in demoBERT, we provide the [Megatron-LM](https://github.com/NVIDIA/Megatron-LM) transformer model finetuned for SQuAD 2.0 task with sparsity and quantization.

The sparse weights are generated by finetuning with INT8 Quantization Aware Training recipe. This feature can be used with the fixed or variable sequence length implementations by passing in `-sp` flag to demoBERT builder.

#### Megatron-LM for Question Answering

##### Example: Megatron-LM Large SQuAD v2.0 with sparse weights for sequence length 384

**Build the TensorRT engine**:

Options specified:
* `--megatron`  : assume Megatron style residuals instead of vanilla BERT.
* `--pickle`    : specify a pickle file containing the PyTorch statedict corresponding to fine-tuned Megatron model.
* `-sp`         : enable sparsity during engine optimization and treat the weights as sparse.
* `--int8 --il` : enable int8 tactics/plugins with interleaving.

```bash
bash ./scripts/download_model.sh 384 v1_1 # BERT-large model checkpoint fine-tuned for SQuAD 1.1
bash ./scripts/download_model.sh pyt megatron-large int8-qat sparse # Megatron-LM model weights
export CKPT_PATH=models/fine-tuned/bert_pyt_statedict_megatron_sparse_int8qat_v21.03.0/bert_pyt_statedict_megatron_sparse_int8_qat
mkdir -p engines && python3 builder_varseqlen.py -c models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1 -b 1 -s 384 -o engines/megatron_large_seqlen384_int8qat_sparse.engine --fp16 --int8 --strict -il --megatron --pickle $CKPT_PATH -v models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/vocab.txt -sp
```

**Ask a question**:
```bash
python3 inference_varseqlen.py -e engines/megatron_large_seqlen384_int8qat_sparse.engine -p "TensorRT is a high performance deep learning inference platform that delivers low latency and high throughput for apps such as recommenders, speech and image/video on NVIDIA GPUs. It includes parsers to import models, and plugins to support novel ops and layers before applying optimizations for inference. Today NVIDIA is open-sourcing parsers and plugins in TensorRT so that the deep learning community can customize and extend these components to take advantage of powerful TensorRT optimizations for your apps." -q "What is TensorRT?" -v models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/vocab.txt -s 256
```

**Evaluate F1 score**:
```bash
python3 inference_varseqlen.py -e engines/megatron_large_seqlen384_int8qat_sparse.engine -s 384 -sq ./squad/dev-v1.1.json -v models/fine-tuned/bert_tf_ckpt_large_qa_squad2_amp_384_v19.03.1/vocab.txt -o ./predictions.json
python3 squad/evaluate-v1.1.py  squad/dev-v1.1.json  ./predictions.json 90
```
Expected output:
```
&&&& PASSED TensorRT BERT Squad Accuracy matches reference.
{"exact_match": 84.03973509933775, "f1": 90.88667129897755}
```

## Performance

### Benchmarking

The following section shows how to run the inference benchmarks for BERT.

#### TensorRT inference benchmark

The inference benchmark is performed on a single GPU by the `inference_benchmark.sh` script, which takes the following steps for each set of model parameters:

1. Downloads checkpoints and builds a TensorRT engine if it does not already exist.

2. Runs 100 warm-up iteration then runs inference for 1000 to 2000 iterations for each batch size specified in the script, selecting the profile best for each size.

**Note:** The time measurements do not include the time required to copy inputs to the device and copy outputs to the host.

To run the inference benchmark script, run:
```bash
bash scripts/inference_benchmark.sh --gpu <arch>
```
Options for `<arch>` are: 'Volta', 'Xavier', 'Turing', 'Ampere'

Note: Some of the configurations in the benchmark script require 16GB of GPU memory. On GPUs with smaller amounts of memory, parts of the benchmark may fail to run.

Also note that BERT Large engines, especially using mixed precision with large batch sizes and sequence lengths may take a couple hours to build.

### Results

The following sections provide details on how we achieved our performance and inference.

#### Inference performance: NVIDIA A100 (40GB)

Our results for BERT were obtained by running the `scripts/inference_benchmark.sh --gpu Ampere` script in the container generated by the TensorRT OSS Dockerfile on NVIDIA A100 with (1x A100 40G) GPUs.

##### BERT Base

| Sequence Length | Batch Size | INT8 Latency (ms) |               |         | FP16 Latency (ms) |               |         |
|-----------------|------------|-----------------|-----------------|---------|-----------------|-----------------|---------|
|                 |            | 95th Percentile | 99th Percentile | Average | 95th Percentile | 99th Percentile | Average |
| 128 | 1 | 0.33 | 0.97 | 0.58 | 0.75 | 0.75 | 0.72 |
| 128 | 2 | 0.78 | 0.79 | 0.63 | 0.84 | 1.07 | 0.84 |
| 128 | 4 | 0.76 | 0.98 | 0.76 | 1.13 | 1.46 | 1.14 |
| 128 | 8 | 1.08 | 1.08 | 0.98 | 1.66 | 1.81 | 1.66 |
| 128 | 12 | 1.26 | 1.63 | 1.27 | 2.07 | 2.07 | 2.07 |
| 128 | 16 | 1.47 | 1.48 | 1.47 | 2.48 | 2.49 | 2.48 |
| 128 | 24 | 2.13 | 2.13 | 2.13 | 3.47 | 3.49 | 3.46 |
| 128 | 32 | 2.54 | 2.83 | 2.54 | 4.37 | 4.40 | 4.34 |
| 128 | 64 | 4.58 | 4.59 | 4.54 | 8.70 | 8.79 | 8.65 |
| 128 | 128 | 9.04 | 9.06 | 8.97 | 17.05 | 17.07 | 16.90 |
| 384 | 1 | 1.15 | 1.15 | 1.15 | 1.43 | 1.44 | 1.43 |
| 384 | 2 | 1.37 | 1.37 | 1.37 | 1.84 | 2.21 | 1.84 |
| 384 | 4 | 1.73 | 1.74 | 1.73 | 2.47 | 2.48 | 2.47 |
| 384 | 8 | 2.51 | 2.51 | 2.51 | 3.77 | 3.80 | 3.76 |
| 384 | 12 | 3.61 | 3.62 | 3.61 | 5.36 | 5.37 | 5.30 |
| 384 | 16 | 4.39 | 4.40 | 4.38 | 7.32 | 7.32 | 7.24 |
| 384 | 24 | 6.24 | 6.24 | 6.23 | 10.50 | 10.51 | 10.41 |
| 384 | 32 | 8.42 | 8.50 | 8.42 | 14.32 | 14.44 | 14.27 |
| 384 | 64 | 16.48 | 16.52 | 16.36 | 27.51 | 27.54 | 27.33 |
| 384 | 128 | 31.71 | 31.78 | 31.58 |  |  |  |

##### BERT Large

| Sequence Length | Batch Size | INT8 Latency (ms) |               |         | FP16 Latency (ms) |               |         |
|-----------------|------------|-----------------|-----------------|---------|-----------------|-----------------|---------|
|                 |            | 95th Percentile | 99th Percentile | Average | 95th Percentile | 99th Percentile | Average |
| 128 | 1 | 1.24 | 1.56 | 1.24 | 1.73 | 2.11 | 1.73 |
| 128 | 2 | 1.49 | 1.49 | 1.49 | 2.20 | 2.20 | 2.20 |
| 128 | 4 | 1.91 | 1.92 | 1.91 | 3.22 | 3.23 | 3.22 |
| 128 | 8 | 2.94 | 2.94 | 2.93 | 4.84 | 4.84 | 4.83 |
| 128 | 12 | 3.34 | 3.34 | 3.34 | 5.95 | 5.96 | 5.90 |
| 128 | 16 | 4.63 | 4.64 | 4.62 | 7.98 | 7.99 | 7.90 |
| 128 | 24 | 5.87 | 5.88 | 5.87 | 11.05 | 11.08 | 10.94 |
| 128 | 32 | 7.99 | 7.99 | 7.98 | 14.74 | 14.77 | 14.59 |
| 128 | 64 | 14.74 | 17.74 | 14.56 | 28.09 | 28.25 | 27.85 |
| 128 | 128 | 28.32 | 23.38 | 28.03 | 54.38 | 54.40 | 54.12 |
| 384 | 1 | 2.80 | 2.80 | 2.80 | 3.49 | 3.49 | 3.48 |
| 384 | 2 | 3.12 | 3.13 | 3.12 | 4.71 | 4.72 | 4.71 |
| 384 | 4 | 4.27 | 4.27 | 4.27 | 6.70 | 6.71 | 6.70 |
| 384 | 8 | 7.66 | 7.67 | 7.66 | 12.41 | 12.53 | 12.37 |
| 384 | 12 | 10.07 | 10.08 | 10.07 | 17.63 | 17.76 | 17.56 |
| 384 | 16 | 13.34 | 13.34 | 13.33 | 23.40 | 23.46 | 23.19 |
| 384 | 24 | 19.36 | 19.38 | 19.22 | 34.34 | 34.36 | 34.10 |
| 384 | 32 | 25.56 | 25.60 | 25.56 | 44.94 | 44.98 | 44.78 |
| 384 | 64 | 49.84 | 49.92 | 49.60 | 87.26 | 87.56 | 86.77 |
| 384 | 128 | 97.66 | 97.78 | 97.06 | 170.85 | 171.00 | 170.08 |

##### Megatron Large with Sparsity

| Sequence Length | Batch Size | INT8 QAT Latency (ms) |               |         |
|-----------------|------------|-----------------|-----------------|---------|
|                 |            | 95th Percentile | 99th Percentile | Average |
| 128 | 1 | 1.16 | 1.46 | 1.17 |
| 128 | 2 | 1.44 | 1.45 | 1.44 |
| 128 | 4 | 1.69 | 1.7 | 1.69 |
| 128 | 8 | 2.34 | 2.34 | 2.34 |
| 128 | 12 | 2.8 | 2.8 | 2.8 |
| 128 | 16 | 3.7 | 3.71 | 3.7 |
| 128 | 24 | 4.63 | 4.63 | 4.62 |
| 128 | 32 | 6.33 | 6.33 | 6.32 |
| 128 | 64 | 11.34 | 11.35 | 11.24 |
| 128 | 128 | 21.18 | 21.19 | 21.06 |
| 384 | 1 | 1.61 | 1.61 | 1.61 |
| 384 | 2 | 2.19 | 2.19 | 2.18 |
| 384 | 4 | 3.31 | 3.31 | 3.31 |
| 384 | 8 | 5.48 | 5.48 | 5.47 |
| 384 | 12 | 7.69 | 7.7 | 7.69 |
| 384 | 16 | 10.02 | 10.02 | 10.01 |
| 384 | 24 | 14.15 | 14.15 | 14.14 |
| 384 | 32 | 18.41 | 18.56 | 18.4 |
| 384 | 64 | 35.71 | 35.73 | 35.44 |
| 384 | 128 | 68.52 | 68.55 | 68.19 |

#### Inference performance: NVIDIA T4 (16GB)

Our results were obtained by running the `scripts/inference_benchmark.sh --gpu Turing` script in the container generated by the TensorRT OSS Dockerfile on NVIDIA T4 with (1x T4 16G) GPUs.

##### BERT Base

| Sequence Length | Batch Size | INT8 Latency (ms) |               |         | FP16 Latency (ms) |               |         |
|-----------------|------------|-----------------|-----------------|---------|-----------------|-----------------|---------|
|                 |            | 95th Percentile | 99th Percentile | Average | 95th Percentile | 99th Percentile | Average |
| 128 | 1 | 1.55 | 1.57 | 1.33 | 2.00 | 2.06 | 1.93 |
| 128 | 2 | 1.78 | 2.06 | 1.75 | 2.54 | 2.58 | 2.49 |
| 128 | 4 | 2.80 | 2.88 | 2.74 | 4.25 | 4.34 | 4.16 |
| 128 | 8 | 4.48 | 4.56 | 4.42 | 8.13 | 8.74 | 7.88 |
| 128 | 12 | 6.28 | 6.31 | 6.12 | 11.67 | 12.12 | 11.30 |
| 128 | 16 | 8.92 | 9.11 | 8.78 | 17.24 | 17.79 | 16.70 |
| 128 | 24 | 12.70 | 12.84 | 12.53 | 24.48 | 24.85 | 24.90 |
| 128 | 32 | 17.90 | 18.41 | 17.59 | 33.02 | 33.51 | 32.65 |
| 128 | 64 | 34.80 | 34.83 | 34.31 | 65.38 | 65.43 | 64.28 |
| 128 | 128 | 68.16 | 68.46 | 67.05 | 130.77 | 131.01 | 129.19 |
| 384 | 1 | 2.47 | 2.53 | 2.43 | 3.76 | 3.81 | 3.69 |
| 384 | 2 | 3.87 | 3.95 | 3.81 | 6.31 | 6.43 | 6.21 |
| 384 | 4 | 7.15 | 7.18 | 6.97 | 12.16 | 12.22 | 12.03 |
| 384 | 8 | 14.09 | 12.11 | 13.73 | 25.45 | 25.83 | 24.94 |
| 384 | 12 | 20.99 | 21.12 | 20.66 | 38.15 | 38.38 | 37.51 |
| 384 | 16 | 27.49 | 27.65 | 27.08 | 50.90 | 51.36 | 50.04 |
| 384 | 24 | 41.93 | 42.17 | 41.36 | 77.25 | 78.16 | 76.05 |
| 384 | 32 | 54.65 | 54.87 | 54.06 | 102.44 | 103.09 | 101.30 |
| 384 | 64 | 109.78 | 110.42 | 108.24 | 200.58 | 201.20 | 198.68 |
| 384 | 128 | 227.46 | 228.80 | 223.92 | 401.33 | 402.14 | 399.24 |

##### BERT Large

| Sequence Length | Batch Size | INT8 Latency (ms) |               |         | FP16 Latency (ms) |               |         |
|-----------------|------------|-----------------|-----------------|---------|-----------------|-----------------|---------|
|                 |            | 95th Percentile | 99th Percentile | Average | 95th Percentile | 99th Percentile | Average |
| 128 | 1 | 3.59 | 3.61 | 3.51 | 5.10 | 5.18 | 5.02 |
| 128 | 2 | 4.93 | 5.03 | 4.83 | 7.72 | 7.73 | 7.58 |
| 128 | 4 | 8.15 | 8.19 | 7.93 | 13.67 | 13.85 | 13.56 |
| 128 | 8 | 14.21 | 14.23 | 13.89 | 26.88 | 27.66 | 26.35 |
| 128 | 12 | 22.41 | 22.47 | 21.91 | 41.04 | 41.29 | 40.30 |
| 128 | 16 | 29.30 | 29.83 | 28.82 | 55.04 | 55.27 | 54.05 |
| 128 | 24 | 44.60 | 44.63 | 43.92 | 81.24 | 82.28 | 79.59 |
| 128 | 32 | 60.88 | 61.48 | 58.97 | 114.13 | 114.47 | 112.78 |
| 128 | 64 | 111.78 | 112.02 | 110.77 | 224.24 | 225.02 | 221.97 |
| 128 | 128 | 223.99 | 224.28 | 222.33 | 417.56 | 418.54 | 415.33 |
| 384 | 1 | 7.18 | 7.27 | 7.07 | 11.74 | 11.96 | 11.51 |
| 384 | 2 | 12.22 | 12.25 | 11.92 | 21.47 | 21.61 | 20.97 |
| 384 | 4 | 35.95 | 36.43 | 35.63 | 42.03 | 42.35 | 41.36 |
| 384 | 8 | 47.06 | 47.22 | 46.41 | 83.16 | 83.51 | 82.06 |
| 384 | 12 | 66.04 | 66.04 | 65.89 | 127.10 | 127.99 | 127.46 |
| 384 | 16 | 87.98 | 88.45 | 87.13 | 164.13 | 165.12 | 161.96 |
| 384 | 24 | 132.56 | 132.96 | 131.24 | 262.76 | 263.68 | 258.96 |
| 384 | 32 | 179.44 | 180.61 | 176.66 | 329.99 | 331.67 | 325.59 |
| 384 | 64 | 352.81 | 353.39 | 350.21 | 684.19 | 686.39 | 674.76 |
| 384 | 128 | 706.85 | 707.73 | 704.38 | 1318.74 | 1320.22 | 1315.10 |

repository: SsisyphusTao/TensorRT

repo_name: SsisyphusTao/TensorRT


text:
# apollo-server-core

[![npm version](https://badge.fury.io/js/apollo-server-core.svg)](https://badge.fury.io/js/apollo-server-core)
[![Build Status](https://circleci.com/gh/apollographql/apollo-server/tree/main.svg?style=svg)](https://circleci.com/gh/apollographql/apollo-server)

This is the core module of the Apollo community GraphQL Server. [Read the docs.](https://www.apollographql.com/docs/apollo-server/)
[Read the CHANGELOG.](https://github.com/apollographql/apollo-server/blob/main/CHANGELOG.md)

repository: diegopacheco/scala-playground

gha_language: Scala

gha_license_id: Unlicense

repo_name: diegopacheco/scala-playground


text:
[uy.klutter.config.typesafe](../index.md) / [com.typesafe.config.Config](index.md) / [value](.)

# value
fun Config.value(key: String): [ConfiguredValue](../-configured-value/index.md) [(source)](https://github.com/kohesive/klutter/blob/master/config-typesafe-jdk6/src/main/kotlin/uy/klutter/config/typesafe/TypesafeConfig_Ext.kt#L21)

Return a value from configuration as a more uniform temporary object that can be checked for existance, and has
additional methods for retrieving values, including with defaults.

repository: drothmaler/klutter

repo_name: drothmaler/klutter


text:
A standard compliant dcm-j2k streaming viewer prototype. See [demo](http://jpambrun.github.io).

## Dependencies
[Modified PDF.js j2k decoder] (https://github.com/jpambrun/jpx-medical)
[Cornerstones interactive medical images library] (https://github.com/jpambrun/cornerstone)

```
git submodule init
git submodule update
bower install
npm install
```

## Streaming requirements
The decoder need to know meaningfull j2k truncation points in order to enable streaming.
These truncation points are currently passed using private DICOM tags:
```
(0069,1012) truncation offset of layer 1 from the beginning of the j2k codestream
(0069,1013) truncation offset of layer 2
(0069,1013) truncation offset of layer 3
```


text:
# SLDS Illustration Lightning Web Component

The [SLDS Illustration component blueprint](https://www.lightningdesignsystem.com/components/illustration/) as a Lightning Web Component. Also usable in Lightning App Builder.

# Installation

Deploy the `illustration` and `illustration-image` components into your org manually or click the button below!

# Usage

- The `illustration` component displays an Illustration that adheres to the blueprint laid out in SLDS. It depends on `illustration-image`.
- The `illustration-image` component displays only an Illustration image with no text.

_Note that `illustration` has size constraints placed on it by SLDS while `illustration-image` will fill the width of its container._

## Image Options

Images are specified via an identifier in the format `category:description`, where `category` and `description` are the [snake_case](https://en.wikipedia.org/wiki/Snake_case) form of the categories and image labels given on the [SLDS Illustration page](https://www.lightningdesignsystem.com/components/illustration/). For an explicit list of all identifiers, see [illustrationImage/images/index.js](./force-app/main/default/lwc/illustrationImage/images/index.js#L24)

See the [SLDS Illustration page](https://www.lightningdesignsystem.com/components/illustration/) for what each identifier renders as well as when to use each image.

repository: geekyakshay/lwc-illustration

repo_name: geekyakshay/lwc-illustration


text:
# Tweet Deleter
Complete script made in Python that allows to delete all the tweets of an account given a date range. For this it makes use of the Twitter API so it is necessary to have a Twitter Developers account
## Configuration
1. Add the API keys in remove-tweets.py file:

```
CONSUMER_KEY = ""
CONSUMER_SECRET = ""
ACCESS_TOKEN_KEY = ""
ACCESS_TOKEN_SECRET = ""
```

2. Modify the date range:

```
range_start = parse_datetime('Sep 10 00:00:00 +0000 2007')
range_end = parse_datetime('Jan 10 00:00:00 +0000 2019')
```

3. Run the script

```
python tweet-deleter.py

repository: rubenRP/tweet-deleter

repo_name: rubenRP/tweet-deleter


text:
### [CVE-2010-2524](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2010-2524)
![](https://img.shields.io/static/v1?label=Product&message=n%2Fa&color=blue)
![](https://img.shields.io/static/v1?label=Version&message=%3D%20n%2Fa%20&color=brighgreen)
![](https://img.shields.io/static/v1?label=Vulnerability&message=n%2Fa&color=brighgreen)

### Description

The DNS resolution functionality in the CIFS implementation in the Linux kernel before 2.6.35, when CONFIG_CIFS_DFS_UPCALL is enabled, relies on a user's keyring for the dns_resolver upcall in the cifs.upcall userspace helper, which allows local users to spoof the results of DNS queries and perform arbitrary CIFS mounts via vectors involving an add_key call, related to a "cache stuffing" issue and MS-DFS referrals.

### POC

#### Reference
- http://www.vmware.com/security/advisories/VMSA-2011-0003.html

#### Github
No PoCs found on GitHub currently.

repository: trickest/cve

gha_language: HTML

repo_name: trickest/cve


text:
# Airship React Native Sample

A basic sample application that integrates the Airship React Native module.

## Setup

1) Install modules: Run `yarn` in repository root

### iOS

1) Run `pod install` in `example/ios`

2) Create the `AirshipConfig.plist` file in `example/ios`

3) Start the webserver in the top-level directory by running `yarn start`

4) Build and run the sample in the `example` directory: `yarn run:ios`

### Android

1) Create the `airshipconfig.properties` file in `example/android/app/src/main/assets`

2) If using FCM, add your `google-services.json` file in `example/android/app`

3) Start the webserver in the top-level directory by running `yarn start`

4) Build and run the sample in the `example` directory: `yarn run:android`

repository: Batareeed/react-native-module

gha_license_id: NOASSERTION

repo_name: Batareeed/react-native-module


text:
# Human mesoderm differentiation
This repository contains scripts for dataset processing and QC for the mesoderm differentiation project.
If you have questions, please contact Pang Wei Koh (<pangwei@cs.stanford.edu>).

## RNA-seq
bulkDataViz.Rmd and scDataViz.Rmd (together with their corresponding .html files) reproduce Figures 2
in the Scientific Data manuscript. scAverageCorrelation.r measures the correlation
of gene expression between the bulk population and the average of single cells.

To process the raw RNA-seq reads, first run STAR\_RSEM\_prep.py and then run\_STAR\_RSEM.py.
This will call STAR (for alignment) and then RSEM (for quantification) on each sample.
Next, run getExpr.py to filter out samples with poor mapping statistics and construct
a matrix of gene expression across samples from the remaining samples.

## ATAC-seq
The ATAC-seq folder contains one file, mesodermATAC.py.

After downloading the data and changing the paths defined at the top of the file appropriately,
run `python mesodermATAC.py generateBDSScript` to generate a .sh file that will call the ATAqC pipeline
on the samples. Figure 3 in the Scientific Data manuscript was taken from the output of the pipeline.

Run `python mesodermATAC.py mergePeaksIDR` followed by `python mesodermATAC.py getPValOnMergedPeaks` after the
pipeline has finished running to obtain a universal list of reproducible peaks across all cell types.

## Surface marker screening
surfaceMarkerViz.Rmd (and its corresponding .html file) reproduces Figure 4 in the Scientific Data manuscript.

repository: kundajelab/mesoderm

repo_name: kundajelab/mesoderm


text:
## Features

- [Tabstops](#tabstops) in the following formats: `$1`, `${1}`
- Tabstops with [placeholders](#placeholders): `${1:foo}`
- Nested tabstops: `$1 ${2:${1:foo}}`
- [Variables](#variables) in the following formats: `$name`, `${name}`
- Variables with placeholders: `${name:Jon Schlinkert}`
- Nested Variables: `${name:${1}}`, `${name:${fullname:Jon Schlinkert}}`
- [Choices](#choices): `${1|one,two,three|}`
- [Variable Transforms](#variable-Transform): `${TM_FILENAME/(.*)\..+$/$1/gim}`
- [Placeholder Transforms](#placeholder-Transform): `${1/^_(.*)/$1/g}`
- One dependency - the brilliant [ansi-colors][]!
- more...!

**Custom Features**

These features are optional and are unique to this library!

- Support for custom variables
- Empty placeholders: `${name:}`
- Custom helper functions
- "Fields"

**Supported Formats**

- [TextMate Snippets](https://macromates.com/textmate/manual/snippets)
- [Atom Snippets](https://flight-manual.atom.io/using-atom/sections/snippets/)
- [VSCode Snippets](https://code.visualstudio.com/docs/editor/userdefinedsnippets)
- [Sublime Text Snippets](http://docs.sublimetext.info/en/latest/extensibility/snippets.html)

## Usage

Note that this library _does not load snippets_ from the file system. You need to pass the snippet string.

```js
const TabStops = require('tabstops');

// pass a string as the first argument
const tabstops = new TabStops('console.log("$1");');

console.log(tabstops.render()); //=> 'console.log("");'

tabstops.set(1, 'It worked!');
console.log(tabstops.render()); //=> 'console.log("It worked!");'

tabstops.set(1, 'Warning!');
console.log(tabstops.render()); //=> 'console.log("Warning!");'
```

## Docs

WIP - user and docs are in progress!!! In the meantime, see the [unit tests](test) for available features and usage examples.

## API

WIP

## Snippet Features

The following documentation is based on the [VSCode Snippets](https://code.visualstudio.com/docs/editor/userdefinedsnippets) and [TextMate Snippets](https://macromates.com/manual/en/snippets) docs.

### Tabstops

With tabstops you can make the editor cursor move inside a snippet. Use `$1`, `$2` to specify cursor locations. The number is the order in which tabstops will be visited, whereas `$0` denotes the final cursor position. Multiple tabstops are linked and updated in sync.

### Placeholders

Placeholders are tabstops with values, like `${1:foo}`. The placeholder text will be inserted and selected such that it can be easily changed. Placeholders can nested, like `${1:another ${2:placeholder}}`.

### Choice

Placeholders may have choices as values. The syntax is a comma-separated enumeration of values, enclosed with the pipe-character, e.g. `${1|one,two,three|}`. When inserted and selected choices will prompt the user to pick one of the values.

### Variables

With `$name` or `${name:default}` you can insert the value of a variable. When a variable isn’t set its *default* or the empty string is inserted. When a variable is unknown (that is, its value is undefined) the name of the variable is inserted instead, and it is transformed into a placeholder.

### Variable-Transform

Transformations allow you to modify the value of a variable before it is being inserted. The definition of a transformation consists of four parts (including the variable to be transformed):

1. The variable to transform
1. A regular expression that is matched against the value of the variable, or the empty string when the variable cannot be resolved.
1. A "format string" that allows to reference matching groups from the regular expression. The format string allows for conditional inserts and simple modifications.
1. Options that are passed to the regular expression

The following sample inserts the name of the current file without its ending, so from `foo.txt` it makes `foo`.

```
${<variable>/<regexp>/<format>/<options>}
${TM_FILENAME/(.*)\..+$/$1/gim}
  |           |         |  |
  |           |         |  |-> options (regex flags)
  |           |         |
  |           |         |-> references the contents of the first
  |           |             capture group
  |           |
  |           |-> regex to capture everything before
  |               the final `.suffix`
  |
  |-> resolves to the filename
```

### Placeholder-Transform

Like a Variable-Transform, a transformation of a placeholder allows changing the inserted text for the placeholder when moving to the next tab stop.

The inserted text is matched with the regular expression and the match or matches - depending on the options - are replaced with the specified replacement format text.

Every occurrence of a placeholder can define its own transformation independently using the value of the first placeholder.

The format for Placeholder-Transforms is the same as for Variable-Transforms.

The following sample removes an underscore at the beginning of the text, so that `_transform` becomes `transform`.

```
${1/^_(.*)/$1/g}
  |   |    |  |-> Options (regex flags)
  |   |    |
  |   |    |-> Replace it with the first capture group
  |   |
  |   |-> Regular expression to capture everything after the underscore
  |
  |-> Placeholder Index
```

### Grammar

Below is the EBNF for snippets. With `\` (backslash) you can escape `$`, `}` and `\`, within choice elements the backslash also escapes comma and pipe characters.

Note that `digit` is a 1-based integer, and `int` is 0-based integer.

```
placeholder ::= tabstop | choice | variable | text
tabstop     ::= '$' int
                | '${' int '}'
                | '${' digit ':' placeholder '}'
                | '${' digit '/' transform '}'
variable    ::= '$' var
                | '${' var '}'
                | '${' var ':' placeholder '}'
                | '${' var '/' transform '}'
transform   ::= regex '/' (format | text)+ '/' flags
format      ::= '$' int
                | '${' int '}'
                | '${' int ':/' helper '}'
                | '${' int ':+' if '}'
                | '${' int ':-' else '}'
                | '${' int ':?' if ':' else '}'
                | '${' int ':' else '}'
choice      ::= '${' digit '|' text (',' text)* '|}'
regex       ::= JavaScript Regular Expression source string
flags       ::= JavaScript Regular Expression options
digit       ::= [1-9]
int         ::= [0-9]
var         ::= [_a-zA-Z][_a-zA-Z0-9]*
custom      ::= var
helper      ::= 'upcase' | 'downcase' | 'capitalize' | custom
text        ::= .*
if          ::= text
else        ::= text
```

repository: jonschlinkert/tabstops

repo_name: jonschlinkert/tabstops


text:
# RKE Backup and Restore Example

This is an example of automation to produce recurring backups in Rancher as well as the automation to perform a recovery from backup.

## Requirements
 - Terraform
 - AWS
 - RKE

 If you are on a Mac you can install Terraform and RKE with Homebrew by running: `brew install terraform` & `brew install rke`.

## Configuring Backup

### Setp 1 - Start two EC2 Servers
First create a file called `terraform.tfvars` that contains the following:

```
ssh_keypair = ""
vpc_id = "
resource_prefix = "my-name-or-unqiue-id"
```

Replace the variables with values that correspond to your environment

Then run:

```
terraform init
```

and subsequently

```
terraform up
```

You should now have two Ubuntu servers running in EC2. Take note of their IP addresses for the next step

### Step 2 - Configure RKE cluster.yml
Edit the file called `cluster.yml` in the root of this repo to reflect the correct IP addresses of the two servers you just created.

Next we want to configure the backup settings for the cluster. Our Terraform plan from above created an S3 bucket we can use for this called `demo-rke-backup-bucket`. Update the section under the key `etcd` in the `cluster.yml` to reflect the correct settings for your AWS account. You'll need to provide it with AWS credentials that the automated job can use to upload. We recommend you create a narrow-scoped IAM user profile for this purpose.

### Step 3 - Deploying Kubernetes and starting Backup Job
Now we can apply our settings with RKE:

```
rke up --ssh-agent-auth
```

This will install Kubernetes on these nodes and configure automated backup. You may need to add the SSH key you are using in AWS to your agent by running `ssh-add /path/to/key`

## Configuring Restore

To preform a restore, we'll re-use much of the information from the previous example to construct the restore command:

```
rke etcd snapshot-restore --config cluster.yml --name snapshot-name \
--s3 --access-key S3_ACCESS_KEY --secret-key S3_SECRET_KEY \
--bucket-name demo-rke-backup-bucket --s3-endpoint s3.amazonaws.com
```

Be sure to replace "snapshot-name" with the correct name of an actual snapshot. Also replace "access-key" and "secret-key" with the same keys we used previously to write the snapshots.

repository: ibrokethecloud/onboarding-content

repo_name: ibrokethecloud/onboarding-content


text:
---
kind: article
created_at: 28 June 2016
title: Shake hands with Belgrade - Day 1
excerpt: "Put the sneakers on, keep the laces tied and indulge yourself into the White City!"
author: Jovana Radovanović
image: 7/siv.jpg

layout: '/blog_single.html'
---

Two days in Belgrade may sounds like a city challenge, but with the help of these guidelines you will manage to snoop around this town and identify its head, middle and base notes.

Put the sneakers on, keep the laces tied and indulge yourself into the White City!

**Day 1.**

**_Top Notes – Architecture_**

Brutalist architecture attracts more and more attention lately. Without going into philosophical debates whether it's a trend or keen interest,
one is certain – these buildings and monuments look like they come from outer space.

[Genex Tower](https://en.wikipedia.org/wiki/Western_City_Gate) is the first brutalistic building that will certainly draw your attention
when arriving in Belgrade. It's one of the highest skyscraper also known as West Gate of Belgrade due to its welcoming tourist position (located near the airport).

![](../7/genex.jpg)

[The Palace of Serbia](https://en.wikipedia.org/wiki/Palace_of_Serbia) (formerly known as Palace of Federation) is another monumental building located
a few bus stations away from Genex. It's a truly brutalist gem and remarkable example of the post World War II architecture.
SIV is home to one of the biggest collection of contemporary FRY artworks, which unfortunately aren't available to general public.

**_Middle Notes – Art_**

If you are looking for some good art place to visit, [U10](http://www.u10.rs/) is the right stop for you.
U10 is an independent exhibition space located in the city centre (Kosovke devojke 3) with vibrant and dynamic program.

![](../7/u_10.jpg)

The place promotes young artist and here you can find all type of art media - from photography and paintings to video installations and sculptures.

![](../7/u_10_2.jpg)

**_Base Notes – Food_**

If you are interested in experimenting with traditional Serbian fast food then ''pljeskavica''
should be on your TO-EAT list.  Stop at the BBQ point ''Halo Leskovac'' (Makedonska 22) and try
Serbian version of burgers served in ''[lepinja](http://www.196flavors.com/2013/10/31/bosnia-and-herzegovina-lepinja/)'' – traditional thin bread.
If you are more of a bistro-lover then [Dokolica Vracar](https://www.facebook.com/DokolicaBistroVracar) (Kralja Milutina 1) is a place to check out.

![](../7/dokolica.jpg)

This small, unpretentious bistro will surprise you with its simple yet delicious menu!

![](../7/dokolica_2.jpg)


text:
## How the code was created

<details>
 <summary>Expand the section</summary>

 The sample is based on [ASP.NET CORE API template](https://learn.microsoft.com/aspnet/core/tutorials/first-web-api?view=aspnetcore-7.0&tabs=visual-studio)

 Because there are two parts - Client and Service, you will have to create 2 separate projects under same solution.

 During the project configuration, specify `Microsoft Identity Platform` inside `Authentication Type` dropdown box. As IDE installs the solution, it might require to install an additional components.

 After the initial project was created, we have to continue with further configuration and tweaking. The most of configuration changes are inside Setup.cs files, so please follow with [Client Setup.cs](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/blob/master/4-WebApp-your-API/4-3-AnyOrg/ToDoListClient/Startup.cs) and [Service Setup.cs](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/blob/master/4-WebApp-your-API/4-3-AnyOrg/TodoListService/Startup.cs) for further details.

 You will have to delete the default controllers and all relevant data from the projects and create Home and TodoList controller for bot Client and Service projects. Refer to the controller sections accordingly.
 </details>

gha_language: PowerShell


text:
# sched_getparam

## Intro
sched_getparam - fetch scheduling parameters of the target process

## Description
sched_getparam is a function used to modify the scheduling parameters of the target process with the given pid according to the changes specified in the second argument, the parameters of the used scheduling policy. It is often used by system administrators to make sure that a certain process is always given the same priority relative to other processes on the system.

One of the advantages of using this function over other methods of setting policy parameters is that it works with any policy, regardless of the number of parameters. This can save time when configuring policies that have a large number of parameters, as the system administrator does not have to manually set each parameter individually.

One of the drawbacks is that it is not an atomic operation. If the pid argument provided is the same as the pid of the calling process, then the operation may take a relatively long time, as the operation must first be carried out on the caller's process, then on the target process. This operation can also lead to race conditions if the pid of the calling process and the pid of the target process are both the same.

## Arguments
* `pid`:pid_t[K] - pid of the process to query the parameters of.
* `param`:struct sched_param*[K+U] - pointer to a struct sched_param to store the policy information in.

### Available Tags
* K - Originated from kernel-space.
* U - Originated from user space (for example, pointer to user space memory used to get it)
* TOCTOU - Vulnerable to TOCTOU (time of check, time of use)
* OPT - Optional argument - might not always be available (passed with null value)

## Hooks
### do_sys_sched_getparam
#### Type
Kprobe + Kretprobe
#### Purpose
Collecting information about the scheduling parameters of a particular process.

## Example Use Case
sched_getparam can be used in a monitoring process which keeps track of the scheduling parameters of processes, in order to ensure that they do not "starve" in terms of resources and can run to completion.

## Issues
The operation is not atomic, which may lead to race conditions with multiple threads trying to access the same process.

## Related Events
* sched_setscheduler - set scheduling policy and parameters of the target process
* sched_get_priority_min - get the minimum priority value for the given scheduling policy

> This document was automatically generated by OpenAI and needs review. It might
> not be accurate and might contain errors. The authors of Tracee recommend that
> the user reads the "events.go" source file to understand the events and their
> arguments better.

repository: aquasecurity/tracee

gha_language: Go

repo_name: aquasecurity/tracee


text:
### [CVE-2020-27302](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-27302)
![](https://img.shields.io/static/v1?label=Product&message=n%2Fa&color=blue)
![](https://img.shields.io/static/v1?label=Version&message=n%2Fa&color=blue)
![](https://img.shields.io/static/v1?label=Vulnerability&message=n%2Fa&color=brighgreen)

### Description

A stack buffer overflow in Realtek RTL8710 (and other Ameba-based devices) can lead to remote code execution via the "memcpy" function, when an attacker in Wi-Fi range sends a crafted "Encrypted GTK" value as part of the WPA2 4-way-handshake.

### POC

#### Reference
- https://www.vdoo.com/blog/realtek-wifi-vulnerabilities-zero-day

#### Github
No PoCs found on GitHub currently.


text:
GaaS REST Documentation
=======================

The Gaffer-as-a-Service REST API services requests to create, get and delete graphs.

## Building gaas-rest
To build gaas-rest without needing to build the entire of gaffer-as-a-service run the command `mvn clean install -pl gaas-rest -am` from the `gaffer-as-a-service` directory.
This command will build gaas-rest with any projects it depends on.

## Using jib plugin to build and push images
The docker image built by Jib plugin you can change the default image using configuration

#To build docker image locally

mvn clean install -DbuildType=dockerBuild -DimageName= -DuserName= -DcredHelper=

# To build docker image and push to docker repository
mvn clean install -DbuildType=build -DimageName=[IMAGE_NAME] -DuserName=[YOUR_DOCKER_USERNAME] -DcredHelper=

## Swagger UI

Run the Spring Boot app locally and access the Swagger dashboard at
http://localhost:8080/swagger-ui/

## Java Code Coverage with JaCoCo Instructions
To generate a code coverage report run the command: `mvn -B verify -P coverage`
The coverage report can be found at: `target/site/jacoco/index.html`

## OpenShift Deployment

#### Deployment Prerequisites

* OpenShift cluster
* OpenShift namespace
* Openshift CLI (oc client)

#### Steps

1. Ensure prerequisites are met
2. Login to the oc client using the `oc login` command via terminal
2. Add the available OpenShift namespace name to /application.properties for the value `namespace`
3. Run `mvn clean install -pl :gaas-rest -Popenshift-deploy`

## Authentication

#### Dev Mode:
When running the API in dev mode, use the 'dev' login details to access the graph endpoints.

Username: javainuse

Password: password

## Integration Tests

Steps to run both OpenShift integration and end-to-end tests (only). This command uses the failsafe plugin and will run
all test classes whose name starts or ends with <i>IT</i>.

1. `oc login` to an OpenShift cluster
2. Set the correct namespace in application.properties
3. Run `mvn verify -pl :gaas-rest -Pintegration-test`

## Prometheus Tests

1. Ensure prerequisites are met
2. Login to the oc client using the `oc login` command via terminal
3. Add the available OpenShift namespace name to /application.properties for the value `namespace`
4. Run `mvn clean install -pl :gaas-rest -Popenshift-deploy`

## Deploying Prometheus to OpenShift
1. Go to gaffer-as-a-service-tools/
2. In the openshift-prometheus.yaml file edit the final line `- targets: ['localhost:8080']`, the `localhost` part can be changed into a specific service that already exists in the same namespace in your cluster. E.g. if the name of your service is test-service you can change the target to `- targets: ['test-service:8080']`.
3. In the command line type in: `oc apply -f openshift-prometheus.yaml`. This should deploy to OpenShift.
4. You may have permission issues with the service account being used, it may need read/write permissions to specific directories in the container. (`oc adm policy add-scc-to-user USERID -z default`)
## Prometheus Endpoints

### check  prometheus targets

click Status dropdown and select Targets

http://example-url/targets

the correct endpoint should be: [http://your_service:8080]/actuator/prometheus

Test Rest API via postman or Kai UI

How to Access Event Logs on OpenShift
=======================
1. Log in to OpenShift using `oc login [token]`.
2. Get name of pod where gaas-rest is running using `oc get pods`.
3. Run `oc port-forward [podName] 8080`. This forwards the pod port 8080 (where GaaS-Rest runs) to localhost:8080.
4. Go to `http://localhost:8080/h2-console/`
5. Ensure that URL field in h2 console page is set to `jdbc:h2:file:./logs/logDB`
6. Log in using username and password

How to Access Swagger On OpenShift
=======================
1. Log in to OpenShift using `oc login [token]`.
2. Get name of pod where gaas-rest is running using `oc get pods`.
3. Run `oc port-forward [podName] 8080`. This forwards the pod port 8080 (where GaaS-Rest runs) to localhost:8080.
4. Go to `http://localhost:8080/swagger-ui/index.html`
5. The swagger UI will then be accessible

GaaS Endpoint Documentation
=======================

This section of documentation aims to provide explanations of the GaaS endpoints as well as example requests and responses to these endpoints.

# Authentication

Authentication is done in the sidecar components and not in GaaS-Rest. Therefore, you should check the documentation of the sidecar
which is being used in conjunction with GaaS-Rest in order to know how authentication works.

# /gaas-rest-service/graphs
This endpoint has 2 operations which can be performed on it - GET and POST

## Get Graphs
Returns a list of graphs which are running in the cluster

`GET localhost:8081/gaas-rest-service/graphs`

Example request using cURL (using the JWT sidecar with bearer token authentication):
```
curl --location --request GET 'localhost:8081/gaas-rest-service/graphs' \
 --header 'Authorization: Bearer abc123.abc123.CDEFG456789' \
 --header 'Content-Type: application/json' \
```

An example of an empty response indicating that there are no graphs in the cluster which could be retrieved:
```
HTTP Status: 200
{
    "graphs": []
}
```

An example of a response returning a list of graphs in the cluster:

```
HTTP Status: 200
{
    "graphs": [
        {
            "graphId": "myexamplegraph",
            "description": "An example graph",
            "url": "http://myexamplegraph-namespace.apps.k8s.example.com/ui",
            "status": "UP",
            "problems": null,
            "configName": "mapStore",
            "restUrl": "https://myexamplegraph-namespace.apps.k8s.example.com/rest"
        }
    ]
}
```

## Create (POST) Graphs
Creates a graph based on the passed in parameters.

`POST localhost:8081/gaas-rest-service/graphs`

The data which must be passed to the POST request:

| Field          | Type           |  Description                                    | Optional           |
| :------------ :|:------------- :| : -------------------------------------------- :| :------------- :|
| graphId        | String         |   This is the name of your graph                 | No
| description    | String         |   This is the description of your graph         | No
| configName     | String         |   The type of graph e.g accumulo or mapStore   | No
| schema         | Object         |   The schema which will be used by the graph   | Yes (Not used by federatedStore)
| proxySubGraphs | Object         |   The proxy sub graphs which will be used by the graph   | Yes (Only used by federatedStore)

Example request using cURL (using the JWT sidecar with bearer token authentication) to create a mapStore graph with a basic schema:
```
curl --location --request POST 'localhost:8081/gaas-rest-service/graphs' \
--header 'Authorization: Bearer abc123.abc123.CDEFG456789' \
--header 'Content-Type: application/json' \
--data-raw '{
   "graphId":"myexamplegraph",
   "description":"An example graph",
   "configName":"mapStore",
   "schema": {
    "edges": {
        "BasicEdge": {
            "source": "vertex",
            "destination": "vertex",
             "description":"BasicEdge",
            "directed": "true",
            "properties": {
                "count": "count"
            }
        }
    },
    "entities": {
        "BasicEntity": {
            "vertex": "vertex",
             "description":"BasicEntity",
            "properties": {
                "count": "count"
            }
        }
    },
    "types": {
        "vertex": {
            "class": "java.lang.String"
        },
        "count": {
            "class": "java.lang.Integer",
            "aggregateFunction": {
                "class": "uk.gov.gchq.koryphe.impl.binaryoperator.Sum"
            }
        },
        "true": {
            "description": "A simple boolean that must always be true.",
            "class": "java.lang.Boolean",
            "validateFunctions": [
                { "class": "uk.gov.gchq.koryphe.impl.predicate.IsTrue" }
            ]
        }
    }
}
}'
```
Example request using cURL (using the JWT sidecar with bearer token authentication) to create a federatedStore graph with a proxy subgraph:
```
{
   "graphId":"myexamplefederatedgraph",
   "description":"A Federated Store",
   "configName":"federated",
   "proxySubGraphs":[
      {
         "graphId":"myproxygraph",
         "host":"myproxygraph-namespace.apps.k8s.example.com",
         "root":"/rest"
      }
   ]
}
```

A successful POST should return:

```
HTTP Status: 201
```

This simply indicates that the graph was created successfully.

# /gaas-rest-service/graphs/{graphId}

Deletes a graph given the ID of a graph. This will delete the graph as well as all its associated resouces in the cluster.

`DELETE /gaas-rest-service/graphs/{graphId}`

Example request using cURL (using the JWT sidecar with bearer token authentication):

```
curl --location --request DELETE 'localhost:8081/gaas-rest-service/graphs/myexamplegraph' \
--header 'Authorization: Bearer abc123.abc123.CDEFG456789'
```

A successful DELETE should return:

```
HTTP Status: 204
```

This indicates that the DELETE operation was successful.

# /gaas-rest-service/storetypes

Returns a list of storetypes which are supported by the API.

`GET /gaas-rest-service/storetypes`

Example request using cURL (using the JWT sidecar with bearer token authentication):

```
curl --location --request GET 'localhost:8081/gaas-rest-service/storetypes' \
--header 'Authorization: Bearer abc123.abc123.CDEFG456789'
```

A successful GET should return:

```
HTTP Status: 200
{
    "storeTypes": [
        {
            "name": "accumulo",
            "parameters": [
                "schema"
            ]
        },
        {
            "name": "federated",
            "parameters": [
                "proxies"
            ]
        },
        {
            "name": "mapStore",
            "parameters": [
                "schema"
            ]
        }
    ]
}
```

This list shows the store types which can be used to create a graph as well as the parameters they require.

Miscellaneous Notes
=======================
- If you want to install a specific chart version this can be done by adding a "--version" flag to the helm install
which occurs in KubernetesObjectFactory.java. Following the --version flag you must specify the version you want to use for example
--version 0.17.1 Currently, the helm install deploys the latest version by default.

repository: gchq/gaffer-experimental

gha_language: Java

repo_name: gchq/gaffer-experimental


text:
# Preact Integrations

A collection of sample apps demonstrating Preact's compatibility with various 3rd party libraries

---

## ✨ Description

This repo contains a collection of simple Preact apps that demonstrate how to use preact with various 3rd party libraries including `react-redux`, `mobx-react`, `react-router`, and more!

The apps are divided into 2 categories: direct and full-compat. Libraries in the "src/direct" directory can be used with `preact` directly and don't require `preact/compat`. Libraries in the "full-compat" directory require aliasing `react` to `preact/compat`.

We are looking for contributors to add more libraries to this repository! If that's you, read on to find out how to get started!

---

## 🤝 Contributing

There are many ways to help our project. Some include:

- Request a library to add
- Adding libraries
- Adding tests for libraries
- File issues for bugs in sample apps
- Fixing bugs in sample apps

Check out our [CONTRIBUTING](CONTRIBUTING.md) guide for details on how to contribute.

---

## 🛠 Setup and building

Follow these steps to setup and run this project locally.

1. Install NPM dependencies:
   ```bash
   npm install
   ```

1. Run our `dev` script to build the project and start the development server:
   ```bash
   npm run dev
   ```

---

## 🏎 Development scripts

Our package.json comes with same basic scripts to help you get started working in our repo. When using `npm` to run our commands, be sure to add ` -- ` before passing in any options to make sure they reach our script and aren't consumed by `npm`.

### dev

The `dev` script will watch the files in `src` and re-build our scripts when one of them changes. If you know what library you are working on and just want to watch those files, pass the name of the library to the dev script like so: `npm run dev preact-router`. This command will start the dev server and only watch the files necessary to re-build the script bundle that includes `preact-router`.

```bash
$ npm run dev -- --help

  Description
    Watch src files of the passed in libraries (defaults to all), build them on change, and run a web server to serve them

  Usage
    $ scripts dev [libraries] [options]

  Options
    -m, --mode    'production' or 'development'  (default development)
    --debug       Print out debugging info  (default false)
    --preact      Path to a preact repo or package to bundle instead of the node_modules version.
		              Must be a path to the directory containing the root package.json in the Preact repo	 or package.
    -h, --help    Displays this message
```

### build

```bash
$ npm run build -- --help

  Description
    Build the bundles that include the libraries passed in (defaults to building all)

  Usage
    $ scripts build [libraries] [options]

  Options
    -m, --mode     'production' or 'development'  (default production)
    -w, --watch    Watch source files and rebuild on change  (default false)
    --debug        Print out debugging info  (default false)
    --preact       Path to a preact repo or package to bundle instead of the node_modules version.
		               Must be a path to the directory containing the root package.json in the Preact repo or package.
    -h, --help     Displays this message
```

### test

The test command just runs `jest` so all [Jest CLI options](https://jestjs.io/docs/en/cli) are supported. The most useful one is passing in a pattern to filter which tests are run. For example, if you only want to run the `preact-router` tests, just pass in the string `preact-router` to only run tests that match that pattern:

```bash
npm run test preact-router
```

### test:debug

Launch `jest` and `puppeteer` with options to enable debugging the tests in Chromium.  These options enable you to call `jestPuppeteer.debug()` in your test to pause jest and pause the browser. See the [`jest-puppeteer` docs for more info](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-environment-puppeteer#globaljestpuppeteerdebug).

Also see the ["Debugging tests" section](./CONTRIBUTING.md#debugging-tests) in the CONTRIBUTING guide.

### serve

```bash
$ npm run serve -- --help

  Description
    Run a development web server

  Usage
    $ scripts serve [options]

  Options
    --debug       Print out debugging info  (default false)
    --preact      Path to a preact repo or package to bundle instead of the node_modules version.
		              Must be a path to the directory containing the root package.json in the Preact repo or package.
    -h, --help    Displays this message
```

---

## 👀 Code Reviews

All submissions, including submissions by project members, require review. It's a great way to learn. We use GitHub pull requests for this purpose. Consult [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more information on using pull requests.

---

## Using with Preact repo

If you are a contributor to [the main Preact repo](https://github.com/preactjs/preact), you can point this repo to your local Preact repo to validate changes you make there. For any of the commands above, specify a `--preact` option to build the integrations website with your local repo. Point the `--preact` option to the top folder of the Preact repo that contains the root `package.json`.

---

## 🥂 License

MIT

repository: preactjs/preact-integrations

repo_name: preactjs/preact-integrations


text:
# Mock
Prototyping better Mock for Pester.

> This is still early in developement, but your opinions are very welcome.

 This allows PowerShell to manage mocks automatically and consistently. This also gives us extremely simple way of explaining mocks. They are simple re-definition of the function. Done. ✓

```PowerShell
New-Mock -FunctionName 'i1' -MockWith { 'fake i1' }

# is the same as
function i1 () {
    # a bit of mock counting code
    #...

    # your body
    'fake i1'
}
```

- Be able to mock function in module scope (or multiple module scopes), and then transition back to the script scope to test the public surface of your module. Done. ✓

```powershell
# define a module l that exports function l1, but does not export function l2
# we want to mock the hidden function l2, but still test l1 from the outside of the
# module
Get-Module l | Remove-Module -Force
New-Module -Name l {
    function l1 { l2 }
    function l2 { "l2 function" }

    Export-ModuleMember -Function l1
} | Import-Module -Force

Save-ScriptScope
Describe 'mock function inside a module and then call it from outside' {
    Invoke-InModuleScope -ModuleName l -ScriptBlock {
        New-Mock -FunctionName 'l2' -MockWith { 'mocked l2' } | out-null
        Invoke-InScriptScope {
            It 'function l1 calls the mocked version of l2' {
                l1 | ShouldBe 'mocked l2'
            }
        }
    }
}
```

See [this example](powershell/readme-example-scoping-simple.ps1) and [annontated version that validates the scopes](powershell/readme-example-scoping-annotated.ps1) in code.

- Detach Mock from Pester, and only make it rely on common Stack mechanism, to allow mock call counting. Partially done.

- Make mock resolve easier to understand, filtering mocks based on ParameterFilter is extremely hard to debug now, I want to see what mocks are available, which were candidates for call, and why they were rejected. Not done.

- Make it possible to relax mock parameters to avoid re-validating parameters, or to avoid parameters with types that we cannot create. Not done.

- Make mock output it's configuration so I can reuse the object for asserting, possibly give mock a name to do the same. Not done.

repository: nohwnd/Mock

repo_name: nohwnd/Mock


text:
Native Types documentation
==========================

Disclaimer: This is a rather informal description.

## Introduction

Following terms are used.
* *Native type*: Type provided by the *ntypes* library, e.g. `int_t` or specializations like `int8_t` or `uint32_t`.
* *Python type*: Type provided by Python, e.g. `int`.

## Integer values

### Operators

Following operators are implemented:

* __Unary operators__: Expressions: `<op> value` resulting in `c`. Such operators require `value` to be *native integers*. `abs`, `+`, `-`, `~`.
* __Binary operators__: Expressions: `lhs <op> rhs` resulting in `c`. Such operators require either `lhs` or `rhs` to be *native integers*. `+`, `-`, `*`, `/`, `//`, `%`, `&`, `|`, `^`, `>>`, `<<`.
* __Inplace operators__: Expressions: `self <op> other`. `+=`, `-=`, `*=`, `/=`, `//=`, `%=`, `&=`, `|=`, `^=`, `>>=`, `<<=`.
* __Relational operators__: `==`, `!=`, `<`, `<=`, `=>`, `>`.

This corresponds to the following Python operators:
`__abs__`, `__pos__`, `__neg__`, `__inv__`, `__ceil__`, `__floor__`, `__round__`, `__trunc__`, `__abs__`, `__add__`, `__sub__`, `__mul__`, `__truediv__`, `__mod__`, `__and__`, `__or__`, `__xor__`, `__lshift__`, `__rshift__`, `__radd__`, `__rsub__`, `__rmul__`, `__rfloordiv__`, `__rtruediv__`, `__rmod__`, `__rand__`, `__ror__`, `__rxor__`, `__rlshift__`, `__rrshift__`, `__iadd__`, `__isub__`, `__imul__`, `__ifloordiv__`, `__itruediv__`, `__imod__`, `__iand__`, `__ior__`, `__ixor__`, `__ilshift__`, `__irshift__`, `__eq__`, `__ne__`, `__lt__`, `__le__`, `__ge__`, `__gt__`.

Following operators have not been implemented as no-operation: `__ceil__`, `__floor__`, `__round__`, `__trunc__`.

All operators except conversion and boolean operators will return a `nint`. To ensure this, and to provide a C-like syntax the `__truediv__` operator will invoke the `__floordiv__` operator.

### Conversion rules

* __Binary operators__:
  1. Both `lhs` and `rhs` are converted into *native types*.
      * If `lhs` is a *Python type* convert it to `rhs`'s *native type*.
      * If `rhs` is a *Python type* convert it to `lhs`'s *native type*.
  2. Result size in bits will be the maximum of the size of `lhs` and `rhs`.
  3. If either `lhs` or `rhs` are unsigned types, then both `lhs` and `rhs` will be treated as unsigned types

* __Relational operators__: Same conversions as for *binary operators*.

* __Inplace operators__:
  1. If `other` is a *Python type*, convert it to `self`'s *native type*.

## Floating-point values

TODO

repository: AlexAltea/ntypes

gha_language: Python

repo_name: AlexAltea/ntypes