pytorch/caffe2/queue/queue_ops.cc
Nikita Shulga 4cb534f92e Make PyTorch code-base clang-tidy compliant (#56892)
Summary:
This is an automatic change generated by the following script:
```
#!/usr/bin/env python3
from subprocess import check_output, check_call
import os

def get_compiled_files_list():
    import json
    with open("build/compile_commands.json") as f:
        data = json.load(f)
    files = [os.path.relpath(node['file']) for node in data]
    for idx, fname in enumerate(files):
        if fname.startswith('build/') and fname.endswith('.DEFAULT.cpp'):
            files[idx] = fname[len('build/'):-len('.DEFAULT.cpp')]
    return files

def run_clang_tidy(fname):
    check_call(["python3", "tools/clang_tidy.py", "-c", "build", "-x", fname,"-s"])
    changes = check_output(["git", "ls-files", "-m"])
    if len(changes) == 0:
        return
    check_call(["git", "commit","--all", "-m", f"NOLINT stubs for {fname}"])

def main():
    git_files = check_output(["git", "ls-files"]).decode("ascii").split("\n")
    compiled_files = get_compiled_files_list()
    for idx, fname in enumerate(git_files):
        if fname not in compiled_files:
            continue
        if fname.startswith("caffe2/contrib/aten/"):
            continue
        print(f"[{idx}/{len(git_files)}] Processing {fname}")
        run_clang_tidy(fname)

if __name__ == "__main__":
    main()
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/56892

Reviewed By: H-Huang

Differential Revision: D27991944

Pulled By: malfet

fbshipit-source-id: 5415e1eb2c1b34319a4f03024bfaa087007d7179
2021-04-28 14:10:25 -07:00

120 lines
5.1 KiB
C++

#include "queue_ops.h"
#include <memory>
#include "caffe2/utils/math.h"
namespace caffe2 {
CAFFE_KNOWN_TYPE(std::shared_ptr<BlobsQueue>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_CPU_OPERATOR(CreateBlobsQueue, CreateBlobsQueueOp<CPUContext>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_CPU_OPERATOR(EnqueueBlobs, EnqueueBlobsOp<CPUContext>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_CPU_OPERATOR(DequeueBlobs, DequeueBlobsOp<CPUContext>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_CPU_OPERATOR(CloseBlobsQueue, CloseBlobsQueueOp<CPUContext>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_CPU_OPERATOR(SafeEnqueueBlobs, SafeEnqueueBlobsOp<CPUContext>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_CPU_OPERATOR(SafeDequeueBlobs, SafeDequeueBlobsOp<CPUContext>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_CPU_OPERATOR(
WeightedSampleDequeueBlobs,
WeightedSampleDequeueBlobsOp<CPUContext>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
OPERATOR_SCHEMA(CreateBlobsQueue).NumInputs(0).NumOutputs(1);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
OPERATOR_SCHEMA(EnqueueBlobs)
.NumInputsOutputs([](int inputs, int outputs) {
return inputs >= 2 && outputs >= 1 && inputs == outputs + 1;
})
.EnforceInplace([](int input, int output) { return input == output + 1; });
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
OPERATOR_SCHEMA(DequeueBlobs)
.NumInputsOutputs([](int inputs, int outputs) {
return inputs == 1 && outputs >= 1;
})
.SetDoc(R"DOC(
Dequeue the blobs from queue.
)DOC")
.Arg("timeout_secs", "Timeout in secs, default: no timeout")
.Input(0, "queue", "The shared pointer for the BlobsQueue")
.Output(0, "blob", "The blob to store the dequeued data");
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
OPERATOR_SCHEMA(CloseBlobsQueue).NumInputs(1).NumOutputs(0);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
OPERATOR_SCHEMA(SafeEnqueueBlobs)
.NumInputsOutputs([](int inputs, int outputs) {
return inputs >= 2 && outputs >= 2 && inputs == outputs;
})
.EnforceInplace([](int input, int output) { return input == output + 1; })
.SetDoc(R"DOC(
Enqueue the blobs into queue. When the queue is closed and full, the output
status will be set to true which can be used as exit criteria for execution
step.
The 1st input is the queue and the last output is the status. The rest are
data blobs.
)DOC")
.Input(0, "queue", "The shared pointer for the BlobsQueue");
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
OPERATOR_SCHEMA(SafeDequeueBlobs)
.NumInputsOutputs([](int inputs, int outputs) {
return inputs == 1 && outputs >= 2;
})
.SetDoc(R"DOC(
Dequeue the blobs from queue. When the queue is closed and empty, the output
status will be set to true which can be used as exit criteria for execution
step.
The 1st input is the queue and the last output is the status. The rest are
data blobs.
)DOC")
.Arg(
"num_records",
"(default 1) If > 1, multiple records will be dequeued and tensors "
"for each column will be concatenated. This requires all tensors in "
"the records to be at least 1D, and to have the same inner dimensions.")
.Input(0, "queue", "The shared pointer for the BlobsQueue")
.Output(0, "blob", "The blob to store the dequeued data")
.Output(1, "status", "Is set to 0/1 depending on the success of dequeue");
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
OPERATOR_SCHEMA(WeightedSampleDequeueBlobs)
.NumInputs(1, INT_MAX)
.NumOutputs(2, INT_MAX)
.SetDoc(R"DOC(
Dequeue the blobs from multiple queues. When one of queues is closed and empty,
the output status will be set to true which can be used as exit criteria for
execution step.
The 1st input is the queue and the last output is the status. The rest are
data blobs.
)DOC")
.Arg("weights", "Weights for sampling from multiple queues")
.Arg(
"table_idx_blob",
"The index of the blob (among the output blob list) "
"that will be used to store the index of the table chosen to read the "
"current batch.");
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
NO_GRADIENT(CreateBlobsQueue);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
NO_GRADIENT(EnqueueBlobs);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
NO_GRADIENT(DequeueBlobs);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
NO_GRADIENT(CloseBlobsQueue);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
NO_GRADIENT(SafeEnqueueBlobs);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
NO_GRADIENT(SafeDequeueBlobs);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
NO_GRADIENT(WeightedSampleDequeueBlobs);
}