KarmaGYZ commented on a change in pull request #11920:
URL: https://github.com/apache/flink/pull/11920#discussion_r419301850



##########
File path: 
flink-external-resource/flink-external-resource-gpu/src/main/java/org/apache/flink/externalresource/gpu/GPUDriver.java
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.externalresource.gpu;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.api.common.externalresource.ExternalResourceDriver;
+import org.apache.flink.configuration.ConfigConstants;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.ExternalResourceOptions;
+import org.apache.flink.util.FlinkRuntimeException;
+import org.apache.flink.util.StringUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.InputStreamReader;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.apache.flink.configuration.ConfigOptions.key;
+
+/**
+ * Driver takes the responsibility to discover GPU resources and provide the 
GPU resource information.
+ * It get the GPU information by executing user-defined discovery script.
+ */
+public class GPUDriver implements ExternalResourceDriver {
+
+       private static final Logger LOG = 
LoggerFactory.getLogger(GPUDriver.class);
+
+       private static final String RESOURCE_NAME = "gpu";
+
+       private static final String DISCOVERY_SCRIPT_PATH_SUFFIX = 
"param.discovery-script.path";
+
+       private static final String DISCOVERY_SCRIPT_ARGS_SUFFIX = 
"param.discovery-script.args";
+
+       @VisibleForTesting
+       static final ConfigOption<String> DISCOVERY_SCRIPT_PATH =
+               
key(ExternalResourceOptions.keyWithResourceNameAndSuffix(RESOURCE_NAME, 
DISCOVERY_SCRIPT_PATH_SUFFIX))
+                       .stringType()
+                       .noDefaultValue();
+
+       @VisibleForTesting
+       static final ConfigOption<String> DISCOVERY_SCRIPT_ARG =
+               
key(ExternalResourceOptions.keyWithResourceNameAndSuffix(RESOURCE_NAME, 
DISCOVERY_SCRIPT_ARGS_SUFFIX))
+                       .stringType()
+                       .noDefaultValue();
+
+       @VisibleForTesting
+       static final ConfigOption<Long> GPU_AMOUNT =
+               
key(ExternalResourceOptions.keyWithResourceNameAndSuffix(RESOURCE_NAME, 
ExternalResourceOptions.EXTERNAL_RESOURCE_AMOUNT_SUFFIX))
+                       .longType()
+                       .defaultValue(0L);

Review comment:
       `GPUDriver` needs to discover the available GPU index in the TM when it 
is instantiated. It's now achieved by executing the discovery script. The 
amount passed to the script is now derived from this configuration(when we 
support fine-grained allocation, it could be calculated from the resourceSpec 
of operators). The `retrieveResourceInfo` should retrieve what operators 
exactly required, although the parameter is now always the `GPU_AMOUNT` because 
we do not support fine-grained allocation.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to