Common

namespace fl

Copyright (c) Facebook, Inc.

and its affiliates. All rights reserved.

This source code is licensed under the BSD-style license found in the LICENSE file in the root directory of this source tree.

and its affiliates. All rights reserved.

This source code is licensed under the BSD-style license found in the LICENSE file in the root directory of this source tree. Logging is a light, multi-level, compile time filterable, logging infrastructure that is similar to glog in output format. It defines two logging macros, one for any logging and the other for more verbose logging. Compile time filter is applied separately to each of the two.

Output format: LMMDD HH:MM:SS.uuuuuu tid filename:##] Log message … L: Log level (Fatal, Critical, Error, Warning, Info) MMDD: month, day HH:MM:SS.uuuuuu: time (24-hour format) with micro-seconds tid: thread ID filename:## the basename of the source file and line number of the LOG message

LOG use examples: LOG(INFO) << “foo bar n=” << 42; Output example: I0206 10:42:21.047293 87072 Logging.h:15 foo bar n=42 Note that LOG(level) only prints when level is <= from value set to Logging::setMaxLoggingLevel(level)

VLOG use example: VLOG(1) << “foo bar n=” << 42; Output example: vlog(1)0206 10:42:21.005439 87072 Logging.h:23 foo bar n=42 Note that VLOG(level) only prints when level is <= from value set to VerboseLogging::setMaxLoggingLevel(level)

and its affiliates. All rights reserved.

This source code is licensed under the BSD-style license found in the LICENSE file in the root directory of this source tree. The configurable memory allocator is obtained by calling: std::unique_ptr<MemoryAllocator> CreateMemoryAllocator(config) Config defines a a set of allocators assembled in a CompositeMemoryAllocator.

Enums

enum ReduceMode

Reduction mode to used for CrossEntropy, AdaptiveSoftMax etc …

Values:

NONE = 0
MEAN = 1
SUM = 2
enum PoolingMode

Pooling method to be used.

Values:

MAX = 0

Use maximum value inside the pooling window.

AVG_INCLUDE_PADDING = 1

Use average value (including padding) inside the pooling window.

AVG_EXCLUDE_PADDING = 2

Use average value (excluding padding) inside the pooling window// Use average value (excluding padding) inside the pooling window.

enum RnnMode

RNN network type.

Values:

RELU = 0
TANH = 1
LSTM = 2
GRU = 3
enum PaddingMode

Values:

SAME = -1

Use smallest possible padding such that out_size = ceil(in_size/stride)

enum DistributedBackend

Values:

GLOO = 0

https://github.com/facebookincubator/gloo

NCCL = 1

https://developer.nvidia.com/nccl

enum DistributedInit

Values:

MPI = 0
FILE_SYSTEM = 1
struct DistributedConstants
#include <Defines.h>

Public Static Attributes

constexpr const char *kMaxDevicePerNode = "MAX_DEVICE_PER_NODE"
constexpr const char *kFilePath = "FILE_PATH"
constexpr const std::size_t kCoalesceCacheSize = ((size_t)(20) << 20)

Defines

AF_CHECK(fn)

Copyright (c) Facebook, Inc.

and its affiliates. All rights reserved.

This source code is licensed under the BSD-style license found in the LICENSE file in the root directory of this source tree.

namespace fl

Copyright (c) Facebook, Inc.

and its affiliates. All rights reserved.

This source code is licensed under the BSD-style license found in the LICENSE file in the root directory of this source tree.

and its affiliates. All rights reserved.

This source code is licensed under the BSD-style license found in the LICENSE file in the root directory of this source tree. Logging is a light, multi-level, compile time filterable, logging infrastructure that is similar to glog in output format. It defines two logging macros, one for any logging and the other for more verbose logging. Compile time filter is applied separately to each of the two.

Output format: LMMDD HH:MM:SS.uuuuuu tid filename:##] Log message … L: Log level (Fatal, Critical, Error, Warning, Info) MMDD: month, day HH:MM:SS.uuuuuu: time (24-hour format) with micro-seconds tid: thread ID filename:## the basename of the source file and line number of the LOG message

LOG use examples: LOG(INFO) << “foo bar n=” << 42; Output example: I0206 10:42:21.047293 87072 Logging.h:15 foo bar n=42 Note that LOG(level) only prints when level is <= from value set to Logging::setMaxLoggingLevel(level)

VLOG use example: VLOG(1) << “foo bar n=” << 42; Output example: vlog(1)0206 10:42:21.005439 87072 Logging.h:23 foo bar n=42 Note that VLOG(level) only prints when level is <= from value set to VerboseLogging::setMaxLoggingLevel(level)

and its affiliates. All rights reserved.

This source code is licensed under the BSD-style license found in the LICENSE file in the root directory of this source tree. The configurable memory allocator is obtained by calling: std::unique_ptr<MemoryAllocator> CreateMemoryAllocator(config) Config defines a a set of allocators assembled in a CompositeMemoryAllocator.

Functions

bool allClose(const af::array &a, const af::array &b, double absTolerance = 1e-5)

Returns true if two arrays are of same type and are element-wise equal within given tolerance limit.

Parameters
  • [ab]: input arrays to compare

  • absTolerance: absolute tolerance allowed

std::string dateTimeWithMicroSeconds()
size_t divRoundUp(size_t numerator, size_t denominator)
class DevicePtr

DevicePtr provides an RAII wrapper for accessing the device pointer of an ArrayFire array.

After calling device() on arrayfire array to get device pointer, the memory is not free until unlock() is called - ‘http://arrayfire.org/docs/group__device__func__device.htm’. DevicePtr provides a std::unique_lock style API which calls the unlock() function in its destructor after getting device pointer. A DevicePtr is movable, but not copyable.

Example Usage :

auto A = af::array(10, 10);
{
    DevicePtr devPtr(A); // calls `.device<>()` on array.
    void* ptr = devPtr.get();
}
// devPtr is destructed and A.unlock() is automatically called

Public Functions

DevicePtr()

Creates a null DevicePtr.

DevicePtr(const af::array &in)

Parameters
  • in: input array to get device pointer

~DevicePtr()

.unlock() is called on the underlying array in destructor

DevicePtr(const DevicePtr &other)
DevicePtr &operator=(const DevicePtr &other)
DevicePtr(DevicePtr &&d)
DevicePtr &operator=(DevicePtr &&other)
bool operator==(const DevicePtr &other) const
void *get() const
class ThreadPool

A simple C++11 Thread Pool implementation.

Source - https://github.com/progschj/ThreadPool

Basic usage:

// create thread pool with 4 worker threads
ThreadPool pool(4);

// enqueue and store future
auto result = pool.enqueue([](int answer) { return answer; }, 42);

// get result from future
std::cout << result.get() << std::endl;

Public Functions

ThreadPool(size_t threads, const std::function<void(size_t)> &initFn = nullptr)

the constructor just launches given amount of workers

Parameters
  • [in] threads: number of threads

  • [in] initFn: initialization code (if any) that will be run on all the threads

template<class F, class ...Args>
auto enqueue(F &&f, Args&&... args)

add new work item to the pool

Parameters
  • [in] f: function to be executed in threadpool

  • [in] args: varadic arguments for the function

~ThreadPool()

destructor joins all threads.