sxjscience commented on a change in pull request #18319: URL: https://github.com/apache/incubator-mxnet/pull/18319#discussion_r440634530
########## File path: src/operator/numpy/np_indexing_op.cu ########## @@ -0,0 +1,574 @@ +/* + * 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. + */ +/*! + * Copyright (c) 2018 by Contributors + * \file np_indexing_op.cu +*/ + +#include "./np_indexing_op.h" +#include <cub/cub.cuh> + +namespace mxnet { +namespace op { + +/*! \brief If there are out-of-bound indices, out will be assigned to 1. + */ +struct is_valid_check { + template<typename DType> + MSHADOW_XINLINE static void Map(int i, char* out, const DType* data, + const DType min, const DType max) { + if (data[i] < min || data[i] > max) *out = 1; + } +}; + +template<typename DType> +bool CheckIndexOutOfBound(mshadow::Stream<gpu> *s, const DType* data_ptr, size_t data_size, + const DType min, const DType max, char* is_valid_ptr) { + using namespace mxnet_op; + int32_t is_valid = 0; + Kernel<set_zero, gpu>::Launch(s, 1, is_valid_ptr); + Kernel<is_valid_check, gpu>::Launch(s, data_size, is_valid_ptr, data_ptr, min, max); + CUDA_CALL(cudaMemcpyAsync(&is_valid, is_valid_ptr, sizeof(char), Review comment: Here, `is_valid` has dtype=`int32_t`, but the `is_valid_ptr` has dtype=`char`. Thus, you may consider to change the dtype of is_valid to char. ---------------------------------------------------------------- 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: [email protected]
