这篇文章涉及mesos如何在原生的mesoscontainerizer和docker containerizer上支持gpu的,以及如果自己实现一个mesos之上的framework capos支持gpu调度的实现原理,(capos是hulu内部的资源调度平台 refer to https://www.cnblogs.com/yanghuahui/p/9304302.html)。

mesos slave在启动的时候需要初始化containerizer的resource,包含cpu/mem/gpu等,这对于mesos containerizer和docker containerizer都是通用的

void Slave::initialize() {
...
Try<Resources> resources = Containerizer::resources(flags);
...
}

然后到了src/slave/containerizer/containerizer.cpp 代码块中, 根据mesos-slave/agent的启动参数flags,调用allocator逻辑

Try<Resources> Containerizer::resources(const Flags& flags)
{
...
// GPU resource.
Try<Resources> gpus = NvidiaGpuAllocator::resources(flags);
if (gpus.isError()) {
return Error("Failed to obtain GPU resources: " + gpus.error());
} // When adding in the GPU resources, make sure that we filter out
// the existing GPU resources (if any) so that we do not double
// allocate GPUs.
resources = gpus.get() + resources.filter(
[](const Resource& resource) {
return resource.name() != "gpus";
});
...
}

src/slave/containerizer/mesos/isolators/gpu/allocator.cpp 会用nvidia的管理gpu的命令nvml以及根据启动参数,返回这台机器上gpu的资源,供之后的调度使用。

// To determine the proper number of GPU resources to return, we
// need to check both --resources and --nvidia_gpu_devices.
// There are two cases to consider:
//
// (1) --resources includes "gpus" and --nvidia_gpu_devices is set.
// The number of GPUs in --resources must equal the number of
// GPUs within --nvidia_gpu_resources.
//
// (2) --resources does not include "gpus" and --nvidia_gpu_devices
// is not specified. Here we auto-discover GPUs using the
// NVIDIA management Library (NVML). We special case specifying
// `gpus:0` explicitly to not perform auto-discovery.
//
static Try<Resources> enumerateGpuResources(const Flags& flags)
{
...
}

因为gpu资源是需要绑定gpu卡number的,gpu资源在调度的数据结构中,是一个set<Gpu>, allocator.go提供allocate和deallocate接口的实现

  Future<Nothing> allocate(const set<Gpu>& gpus)
{
set<Gpu> allocation = available & gpus; if (allocation.size() < gpus.size()) {
return Failure(stringify(gpus - allocation) + " are not available");
} available = available - allocation;
allocated = allocated | allocation; return Nothing();
} Future<Nothing> deallocate(const set<Gpu>& gpus)
{
set<Gpu> deallocation = allocated & gpus; if (deallocation.size() < gpus.size()) {
return Failure(stringify(gpus - deallocation) + " are not allocated");
} allocated = allocated - deallocation;
available = available | deallocation; return Nothing();
}

但是封装到上层,供containerizer调用的时候,指定需要allocate的gpu number就可以

Future<set<Gpu>> NvidiaGpuAllocator::allocate(size_t count)
{
// Need to disambiguate for the compiler.
Future<set<Gpu>> (NvidiaGpuAllocatorProcess::*allocate)(size_t) =
&NvidiaGpuAllocatorProcess::allocate; return process::dispatch(data->process, allocate, count);
}

但是deallocate仍然需要显示指定需要释放哪些gpu

Future<Nothing> NvidiaGpuAllocator::deallocate(const set<Gpu>& gpus)
{
return process::dispatch(
data->process,
&NvidiaGpuAllocatorProcess::deallocate,
gpus);
}

然后如果作业是用docker containerizer,可以看到src/slave/containerizer/docker.cpp中调用gpu的逻辑

Future<Nothing> DockerContainerizerProcess::allocateNvidiaGpus(
const ContainerID& containerId,
const size_t count)
{
if (!nvidia.isSome()) {
return Failure("Attempted to allocate GPUs"
" without Nvidia libraries available");
} if (!containers_.contains(containerId)) {
return Failure("Container is already destroyed");
} return nvidia->allocator.allocate(count)
.then(defer(
self(),
&Self::_allocateNvidiaGpus,
containerId,
lambda::_1));
}

所以之上,就是在slave中启动的时候加载确认gpu资源,然后在启动containerizer的时候,可以利用slave中维护的gpu set资源池,去拿到资源,之后启动作业。

那capos是如何实现的呢,capos是hulu内部的资源调度平台(refer to https://www.cnblogs.com/yanghuahui/p/9304302.html),因为自己实现了mesos的capos containerizer,我们的做法是,在mesos slave注册的时候显示的通过参数或者自动探测的机制,发现gpu资源,然后用--resources=gpu range的形式启动mesos agent,这样offer资源的gpu在capos看来就是一个range,可以类似使用port资源的方式,来调度gpu,在capos containerizer中,根据调度器指定的gpu range,去绑定一个或者多个gpu资源到docker nvidia runtime中。完成gpu调度功能。

mesos支持gpu代码分析以及capos支持gpu实现的更多相关文章

  1. JQuery html API支持解析执行Javascript脚本功能实现-代码分析

    JQuery html用法(功能类似innerHTML) 开发中需要使用Ajax技术来更新页面局部区域, 使用的方法是ajax获取html代码段(字符串),然后将这个html代码段作为参数,传入目标D ...

  2. 转 Unity企业级支持案例与分析

    Unity大中华区技术支持总监张黎明以“Unity企业级支持案例与分析”为主题进行了分享. 以下为演讲实录: 张黎明:非常感谢大家来参加今年的Unite,其实我现在看到有的朋友已经不是第一次来参加Un ...

  3. unite2017《Unity企业级支持案例与分析》

    在今天举办的Unite2017开发者大会上,Unity大中华区技术支持总监张黎明以"Unity企业级支持案例与分析"为主题进行了分享. 以下为演讲实录: 张黎明:非常感谢大家来参加 ...

  4. phpStorm支持CodeIgniter代码提示/自动完成

    下载这个文件phpstorm-ci-ac 或者去github下载解压里面的三个文件到ci根目录下然后找到这三个文件 system\core\Controller.phpsystem\core\Mode ...

  5. Eclipse支持Jquery代码提示(JqeuryWTP)

    问题描述:        Eclipse支持Jquery代码提示   问题解决: 下载 JqueryWTP.jar文件         文件替换        在Eclipse/plugin 路径下, ...

  6. 让wordpress分类和标签的描述支持HTML代码

    默认 WordPress 后台分类和标签的编辑页面,分类和标签的描述是不支持 HTML 代码的,我们可以通过在当前主题的 functions.php 文件添加如下代码让分类和标签的描述支持 HTML ...

  7. LiveBlox无需代码的开发工具--支持win macos ubuntu等开发环境--

    LiveBlox无需代码的开发工具-支持windows macos ubuntu. 强大 灵活 易于使用 视频简介:LiveBlox Develop Technology Without Coding ...

  8. Typecho-Material主题不支持Kotlin代码高亮的解决方案

    Typecho-Material主题不支持Kotlin代码高亮的解决方案 Overview 最近通过Typecho搭建了一个Blog,采用了 Material主题,其他的都挺好,也挺喜欢这个主题,但是 ...

  9. Sublime text代码补全插件(支持Javascript、JQuery、Bootstrap框架)

    Sublime text代码补全插件(支持Javascript.JQuery.Bootstrap框架)   插件名称:javascript-API-Completions 支持Javascript.J ...

随机推荐

  1. 主要的Ajax框架都有什么?

    *  Dojo(dojotoolkit.org):* Prototype和Scriptaculous (www.prototypejs.org和script.aculo.us):* Direct We ...

  2. 微信小程序(一):编写58同城页面

    2018.3.25 这个时间我觉得更具58页面进行模仿. 微信小程序,标题更改在app.json文件中window属性. window用于设置小程序的状态栏.导航条.标题.窗口背景色.注意在app.j ...

  3. spark原理

    SparkContext将应用程序代码分发到各Executors,最后将任务(Task)分配给executors执行 Application: Appliction都是指用户编写的Spark应用程序, ...

  4. 磨人的Fragment的转换

    磨人的Fragment的转换 本次任务是 程序运行之后将第一个Fragment加载出来 然后点击"SHOW NEXT PAGE"切换到第二个Fragment 当再次点击按钮时下方出 ...

  5. LINUX 系统下部署 NFS服务

    NFS服务 NFS,是Network File System的简写,即网络文件系统.也被称为NFS: NFS允许一个系统在网络上与他人共享目录和文件. NFS通常运行于2049端口. 部署NFS 前提 ...

  6. 有return的情况下try catch finally的执行顺序(转)

    结论:1.不管有没有出现异常,finally块中代码都会执行:2.当try和catch中有return时,finally仍然会执行:3.finally是在return后面的表达式运算后执行的(此时并没 ...

  7. JS模块化工具require.js教程(一):初识require.js

    随着网站功能逐渐丰富,网页中的js也变得越来越复杂和臃肿,原有通过script标签来导入一个个的js文件这种方式已经不能满足现在互联网开发模式,我们需要团队协作.模块复用.单元测试等等一系列复杂的需求 ...

  8. python之路(十一)-socke开发

    socket简介 socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄,应用程序通常通过"套接字"向网络发出请求或者应答网络请求. so ...

  9. 微软develop apps在QQ上部分功能的实现

    最近我对微软的develop apps的文档进行了简读,在感叹UWP在支持服务上的全面的同时,我不禁在在常用的APP上对于这些功能支持进行了部分的寻找对应.而我进行功能对照的,就是平时很常用的一款手机 ...

  10. 开机后Android应用自动启动

    一.需求 在应用开发过程中,有客户提出在设备开机后自动启动应用. 二.实现方法 实现方案:安卓系统每次开机的时候都会发送一个广播,监听这个广播,广播事件触发启动应用程序. 监听音频广播而不是启动广播, ...