|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -#include <cudf/types.hpp> |
18 | 17 | #include <legate.h>
|
19 | 18 |
|
20 | 19 | #include <arrow/compute/api.h>
|
21 |
| -#include <cudf/unary.hpp> |
22 | 20 |
|
23 |
| -#include <legate_dataframe/core/column.hpp> |
24 |
| -#include <legate_dataframe/core/library.hpp> |
25 | 21 | #include <legate_dataframe/core/table.hpp>
|
26 | 22 | #include <legate_dataframe/core/task_argument.hpp>
|
27 | 23 | #include <legate_dataframe/core/task_context.hpp>
|
|
30 | 26 | namespace legate::dataframe {
|
31 | 27 | namespace task {
|
32 | 28 |
|
33 |
| -class CastTask : public Task<CastTask, OpCode::Cast> { |
34 |
| - public: |
35 |
| - static void cpu_variant(legate::TaskContext context) |
36 |
| - { |
37 |
| - TaskContext ctx{context}; |
38 |
| - const auto input = argument::get_next_input<PhysicalColumn>(ctx); |
39 |
| - auto output = argument::get_next_output<PhysicalColumn>(ctx); |
40 |
| - |
41 |
| - auto cast = ARROW_RESULT(arrow::compute::Cast( |
42 |
| - input.arrow_array_view(), output.arrow_type(), arrow::compute::CastOptions::Unsafe())); |
43 |
| - if (get_prefer_eager_allocations()) { |
44 |
| - output.copy_into(std::move(cast.make_array())); |
45 |
| - } else { |
46 |
| - output.move_into(std::move(cast.make_array())); |
47 |
| - } |
48 |
| - } |
49 |
| - |
50 |
| - static void gpu_variant(legate::TaskContext context) |
51 |
| - { |
52 |
| - TaskContext ctx{context}; |
53 |
| - |
54 |
| - const auto input = argument::get_next_input<PhysicalColumn>(ctx); |
55 |
| - auto output = argument::get_next_output<PhysicalColumn>(ctx); |
56 |
| - cudf::column_view col = input.column_view(); |
57 |
| - std::unique_ptr<cudf::column> ret = cudf::cast(col, output.cudf_type(), ctx.stream(), ctx.mr()); |
58 |
| - if (get_prefer_eager_allocations()) { |
59 |
| - output.copy_into(std::move(ret)); |
60 |
| - } else { |
61 |
| - output.move_into(std::move(ret)); |
62 |
| - } |
63 |
| - } |
64 |
| -}; |
65 |
| - |
66 |
| -cudf::unary_operator arrow_to_cudf_unary_op(std::string op) |
| 29 | +/*static*/ void CastTask::cpu_variant(legate::TaskContext context) |
67 | 30 | {
|
68 |
| - // Arrow unary operators taken from the below list, |
69 |
| - // where an equivalent cudf unary operator exists. |
70 |
| - // https://arrow.apache.org/docs/cpp/compute.html#element-wise-scalar-functions |
71 |
| - // https://docs.rapids.ai/api/libcudf/stable/group__transformation__unaryops |
72 |
| - std::unordered_map<std::string, cudf::unary_operator> arrow_to_cudf_ops = { |
73 |
| - {"sin", cudf::unary_operator::SIN}, {"cos", cudf::unary_operator::COS}, |
74 |
| - {"tan", cudf::unary_operator::TAN}, {"asin", cudf::unary_operator::ARCSIN}, |
75 |
| - {"acos", cudf::unary_operator::ARCCOS}, {"atan", cudf::unary_operator::ARCTAN}, |
76 |
| - {"sinh", cudf::unary_operator::SINH}, {"cosh", cudf::unary_operator::COSH}, |
77 |
| - {"tanh", cudf::unary_operator::TANH}, {"asinh", cudf::unary_operator::ARCSINH}, |
78 |
| - {"acosh", cudf::unary_operator::ARCCOSH}, {"atanh", cudf::unary_operator::ARCTANH}, |
79 |
| - {"exp", cudf::unary_operator::EXP}, {"ln", cudf::unary_operator::LOG}, |
80 |
| - {"sqrt", cudf::unary_operator::SQRT}, {"ceil", cudf::unary_operator::CEIL}, |
81 |
| - {"floor", cudf::unary_operator::FLOOR}, {"abs", cudf::unary_operator::ABS}, |
82 |
| - {"round", cudf::unary_operator::RINT}, {"bit_wise_not", cudf::unary_operator::BIT_INVERT}, |
83 |
| - {"invert", cudf::unary_operator::NOT}, {"negate", cudf::unary_operator::NEGATE}}; |
84 |
| - |
85 |
| - if (arrow_to_cudf_ops.find(op) != arrow_to_cudf_ops.end()) { return arrow_to_cudf_ops[op]; } |
86 |
| - throw std::invalid_argument("Could not find cudf binary operator matching: " + op); |
87 |
| - return cudf::unary_operator::ABS; |
88 |
| -} |
89 |
| - |
90 |
| -class UnaryOpTask : public Task<UnaryOpTask, OpCode::UnaryOp> { |
91 |
| - public: |
92 |
| - static void cpu_variant(legate::TaskContext context) |
93 |
| - { |
94 |
| - TaskContext ctx{context}; |
95 |
| - |
96 |
| - auto op = argument::get_next_scalar<std::string>(ctx); |
97 |
| - const auto input = argument::get_next_input<PhysicalColumn>(ctx); |
98 |
| - auto output = argument::get_next_output<PhysicalColumn>(ctx); |
99 |
| - auto result = |
100 |
| - ARROW_RESULT(arrow::compute::CallFunction(op, {input.arrow_array_view()})).make_array(); |
101 |
| - if (get_prefer_eager_allocations()) { |
102 |
| - output.copy_into(std::move(result)); |
103 |
| - } else { |
104 |
| - output.move_into(std::move(result)); |
105 |
| - } |
| 31 | + TaskContext ctx{context}; |
| 32 | + const auto input = argument::get_next_input<PhysicalColumn>(ctx); |
| 33 | + auto output = argument::get_next_output<PhysicalColumn>(ctx); |
| 34 | + |
| 35 | + auto cast = ARROW_RESULT(arrow::compute::Cast( |
| 36 | + input.arrow_array_view(), output.arrow_type(), arrow::compute::CastOptions::Unsafe())); |
| 37 | + if (get_prefer_eager_allocations()) { |
| 38 | + output.copy_into(std::move(cast.make_array())); |
| 39 | + } else { |
| 40 | + output.move_into(std::move(cast.make_array())); |
106 | 41 | }
|
| 42 | +} |
107 | 43 |
|
108 |
| - static void gpu_variant(legate::TaskContext context) |
109 |
| - { |
110 |
| - TaskContext ctx{context}; |
111 |
| - |
112 |
| - auto op = argument::get_next_scalar<std::string>(ctx); |
113 |
| - const auto input = argument::get_next_input<PhysicalColumn>(ctx); |
114 |
| - auto output = argument::get_next_output<PhysicalColumn>(ctx); |
115 |
| - cudf::column_view col = input.column_view(); |
116 |
| - std::unique_ptr<cudf::column> ret = |
117 |
| - cudf::unary_operation(col, arrow_to_cudf_unary_op(op), ctx.stream(), ctx.mr()); |
118 |
| - if (get_prefer_eager_allocations()) { |
119 |
| - output.copy_into(std::move(ret)); |
120 |
| - } else { |
121 |
| - output.move_into(std::move(ret)); |
122 |
| - } |
| 44 | +/*static*/ void UnaryOpTask::cpu_variant(legate::TaskContext context) |
| 45 | +{ |
| 46 | + TaskContext ctx{context}; |
| 47 | + |
| 48 | + auto op = argument::get_next_scalar<std::string>(ctx); |
| 49 | + const auto input = argument::get_next_input<PhysicalColumn>(ctx); |
| 50 | + auto output = argument::get_next_output<PhysicalColumn>(ctx); |
| 51 | + auto result = |
| 52 | + ARROW_RESULT(arrow::compute::CallFunction(op, {input.arrow_array_view()})).make_array(); |
| 53 | + if (get_prefer_eager_allocations()) { |
| 54 | + output.copy_into(std::move(result)); |
| 55 | + } else { |
| 56 | + output.move_into(std::move(result)); |
123 | 57 | }
|
124 |
| -}; |
| 58 | +} |
125 | 59 |
|
126 | 60 | } // namespace task
|
127 | 61 |
|
128 | 62 | LogicalColumn cast(const LogicalColumn& col, cudf::data_type to_type)
|
129 | 63 | {
|
130 |
| - if (!cudf::is_supported_cast(col.cudf_type(), to_type)) { |
131 |
| - throw std::invalid_argument("Cannot cast column to specified type"); |
132 |
| - } |
133 |
| - |
134 | 64 | auto runtime = legate::Runtime::get_runtime();
|
135 | 65 | legate::AutoTask task =
|
136 | 66 | runtime->create_task(get_library(), task::CastTask::TASK_CONFIG.task_id());
|
|
0 commit comments